How to work with settings in Django - python

I want to keep some global settings for my project in Django. I need to have access to these settings from the code. For example, I need to set a current theme for my site that I can set using admin console or from the code. Or I need to set a tagline that will show in the header of all pages. I suppose I should use models for keeping the settings but I can't realize how I should better do it.

There are quite some packages that store settings in models, pick the one that works best for you:
http://pypi.python.org/pypi?:action=search&term=django+settings&submit=search

If you are okay with changing these setting programmatically via settings.py you should do that. However, if you want to change these settings via the Admin Console, you should use models.

Related

Web2py layout configuration settings

The web2py online book in Chapter 3 Overview says that in the scaffolding application, values for response.title, response.meta.author, etc, are set in the file models/menu.py. While previous versions of Web2py did include the settings in menu.py, in v.2.18.5 the default values are not set in this file. While some of the settings, such as response.meta.author etc are defined in models/db.py, response.title and response.subtitle could not be found in db.py also. The online book does say that these can be defined in any model file. Can someone advise where these settings are now defined?
It appears that those items are no longer defined in the scaffolding app. The default layout simply using request.application as the page title if request.title is not defined. Feel free to define those items wherever, or not at all.

Start Django with different setting values

I am writing test for my Django app. I want to start Django with different settings value and run tests for each case. (eg one test for settings.ALLOW_ROBOTS=True and another test for settings.ALLOW_ROBOTS=False). I am not interested in overriding the value at run time. I want to start the server with different settings value each time. Does Django provide a way to accomplish this?
You can choose which settings.py file to use with DJANGO_SETTINGS_MODULE; you can have many that import * from a main one, and then change what needs to be changed.
Alternatively, settings.py is just a Python file. You can get values of settings from environment variables, if you want:
import os
ALLOW_ROBOTS = bool(os.getenv('ALLOW_ROBOTS', False))
And then change that environment variable from Travis.
If I understand your question correctly, you would like to be able to use multiple settings modules. If so, setting the DJANGO_SETTINGS_MODULE environment variable before starting the server is likely what you need.

What is the Django HOST_DOMAIN setting for?

Despite googling I can't find any documentation for the Django HOST_DOMAIN setting in the settings.py.
I am going through a settings.py file I have been given and this is the only part of the file I am not 100% clear on.
You can find out what are all the django specific settings at the settings reference which lists all the settings variables (and their defaults) that are set by django.
Since settings.py is just any other Python module, you are free to define your own variables and import them in your code with:
from django.conf import settings
settings.MY_CUSTOM_SETTING
Third party applications can also define their own settings, which you can modify by entering the specific value in settings.py.
It sounds like HOST_DOMAIN is one such custom setting.
That is not a Django setting.
It's perfectly good practice to define your own project-specific settings inside settings.py, and that is presumably what the original developer did here.

Django: Add my own form to the admin backend?

I'm using the Django Admin module. It displays a list of models to edit by app. I would like to add another form to this list. It won't edit a specific model, but it will edit settings that are stored in the database. Is this possible?
You may check out Django Live Settings. It was split out of the Satchmo project and looks to do what you're looking for.
Otherwise, you may look into Overriding the Django Admin Templates. You could just override the index template and add your links to the bottom.

Including satchmo-livesettings in main django-admin site

I plan to use the sachmo-livesettings module in my django application (not using or related to satchmo). In the satchmo store the livesettings are visible on the main django-admin site. When adding livesettings to my app, though I can access them directly using a dedicated url (e.g. ../settings) I don't manage to make them visible on the main django admin site in the menu on the right side. Do you have any ideas how to include a livesettings overview on the admin site?
There is not much documentation on how to use livesettings, do you have any links to documents about satchmo-livesettings and django-admin. I'm particularly interested on how to add things on the right side (where normally the history of changed model objects is displayed).
Thanks
I'm not too familiar with the satchmo specific bits, but generally the way you handle this kind of thing in Django is by overriding admin templates and creating your own /admin/ urls/views.

Categories

Resources