How to set up a PostgreSQL database in Django

You need to install psycopg2 Python library. Installation Download http://initd.org/psycopg/, then install it under Python PATH After downloading, easily extract the tarball and: $ python setup.py install Or if you wish, install it by either easy_install or pip. (I prefer to use pip over easy_install for no reason.) $ easy_install psycopg2 $ pip install psycopg2 … Read more

What’s the difference between `from django.conf import settings` and `import settings` in a Django project

import settings will import the first python module named settings.py found in sys.path. Usually (in default django setups) it allows access only to your site defined settings file, which overwrites django default settings (django.conf.global_settings). So, if you try to access a valid django setting not specified in your settings file you will get an error. … Read more

ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

I figured that the DJANGO_SETTINGS_MODULE had to be set some way, so I looked at the documentation (link updated) and found: export DJANGO_SETTINGS_MODULE=mysite.settings Though that is not enough if you are running a server on heroku, you need to specify it there, too. Like this: heroku config:set DJANGO_SETTINGS_MODULE=mysite.settings –account <your account name> In my specific … Read more

Can I access constants in settings.py from templates in Django?

If it’s a value you’d like to have for every request & template, using a context processor is more appropriate. Here’s how: Make a context_processors.py file in your app directory. Let’s say I want to have the ADMIN_PREFIX_VALUE value in every context: from django.conf import settings # import the settings file def admin_media(request): # return … Read more