Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:57:02+00:00 2026-06-18T03:57:02+00:00

I am working on creating a Django forums project and I have a settings

  • 0

I am working on creating a Django forums project and I have a “settings” app which access the database for a table called settings.

The table is setup with a verbose_name, name, and value columns. The first is simply a name to be displayed to admins, the second is the name that the setting is accessed by (and is the primary key on the table.)

Now, I have some settings which are boolean, some which are integers, and some of which are string. However, value is a TEXT type in the Database so Django is returning it as a string. Right now I have this implementation to convert booleans into the Python boolean type:

class SettingsMiddleware:
    def process_request(self, request):
        request.settings = {}
        settings = Setting.objects.all()

        for setting in settings:
            if setting.value == ("True" or "1"):
                setting.value = True
            if setting.value == ("False" or "0"):
                setting.value = False

            request.settings[setting.name] = setting.value

        return None

So I have two questions:

  1. Is there a better way to go about this?
  2. How can I determine whether the string contains an integer? I know that I can convert it to an integer with int() if it is valid, but how can I tell whether or not it is valid?

Obviously, regarding question number two, I would remove the or “1” and or “0” bits of the current evaluation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:57:04+00:00Added an answer on June 18, 2026 at 3:57 am

    It seems to me that ast.literal_eval might be useful to you.

    >>> import  ast
    >>> ast.literal_eval("1")
    1
    >>> ast.literal_eval("0")
    0
    >>> ast.literal_eval("True")
    True
    >>> ast.literal_eval("False")
    False
    >>> ast.literal_eval("'foobar'")
    'foobar'
    >>> ast.literal_eval("1.2")
    1.2
    >>> ast.literal_eval("1.2e3")
    1200.0
    >>> ast.literal_eval("1,2")
    (1, 2)
    >>> ast.literal_eval("[1,2]")
    [1, 2]
    >>> ast.literal_eval("[1,2,(1,2)]")
    [1, 2, (1, 2)]
    >>> ast.literal_eval("1f")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/ast.py", line 49, in literal_eval
        node_or_string = parse(node_or_string, mode='eval')
      File "/usr/local/lib/python2.7/ast.py", line 37, in parse
        return compile(source, filename, mode, PyCF_ONLY_AST)
      File "<unknown>", line 1
        1f
         ^
    SyntaxError: unexpected EOF while parsing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a django project that, along with having a database for
I have a Django form wizard working nicely for creating content of one of
I have been working creating a new project static web site and was wondering
I am working on creating a website in Django which consists of two parts:
I am working on creating a form which pulls data from a database, and
I am working on creating a web app that will query event logs on
I’m working on creating a full-screen 3-D app (based on Johnny Lee's Wii head
I am working on creating a simple contest submission system using django. This is
I am working through the Django tutorials , and now I am at creating
I'm working on an intranet django project (not using GAE) for a company that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.