Questions tagged [django-settings]

A Django settings file is a Python module with module-level variables that contains all the configuration of your Django installation such as, Databases, Installed apps and Media and Static location to name a few.

Django settings file is a Python module with module-level variables that contains all the configuration of your Django installation such as: Databases, Installed apps and Media and Static location to name a few.

Here are a couple of example settings, extracted from the documentation:

DEBUG = False
DEFAULT_FROM_EMAIL = 'webmaster@example.com'
TEMPLATE_DIRS = ('/home/templates/mike', '/home/templates/john')
923 questions
61
votes
8 answers

sqlite3.OperationalError: unable to open database file

I get this error when setting up a server in Django. It is sqlite3 which means it should create the .db file but it doesn't seem to be doing so. I've stipulated SQLite as the backend and an absolute file path for where to put it, but no luck. Is…
Chris
  • 11,819
  • 19
  • 91
  • 145
59
votes
6 answers

Page not found 404 Django media files

I am able to upload the files to media folder( '/peaceroot/www/media/') that I have set up in settings.py as below MEDIA_ROOT = '/peaceroot/www/media/' MEDIA_URL = '/media/' But through admin I tried to access the uploaded image…
57
votes
5 answers

django settings per application - best practice?

this is somewhat related to this question Why is django's settings object a LazyObject? In my django project i have several applications. Each application can have its own non-trivial settings file. proj/ proj/ settings.py app/ …
w--
  • 6,427
  • 12
  • 54
  • 92
51
votes
7 answers

Django ALLOWED_HOSTS IPs range

Is there a way to set a range of ALLOWED_HOSTS IPs in django? Something like this: ALLOWED_HOSTS = ['172.17.*.*']
Alex T
  • 4,331
  • 3
  • 29
  • 47
50
votes
1 answer

Django: Check if settings variable is set

Here is an example of what I'm trying to achieve. The desired effect is that a particular feature should take effect if and only if its relevant setting exists is defined. Otherwise, the feature should be disabled. settings.py: SOME_VARIABLE =…
Teekin
  • 12,581
  • 15
  • 55
  • 67
47
votes
8 answers

How can I correctly set DJANGO_SETTINGS_MODULE for my Django project (I am using virtualenv)?

I am having some trouble setting the DJANGO_SETTINGS_MODULE for my Django project. I have a directory at ~/dev/django-project. In this directory I have a virtual environment which I have set up with virtualenv, and also a django project called…
Deonomo
  • 1,583
  • 3
  • 16
  • 25
47
votes
1 answer

Django default_from_email name

I am looking to add a name to my default_from_email address in Django and wanted to know whether you do this through the settings.py file? you have your different options. DEFAULT_FROM_EMAIL EMAIL_HOST EMAIL_PASSWORD ... but the email result still…
ApPeL
  • 4,801
  • 9
  • 47
  • 84
47
votes
1 answer

how to check DEBUG true/false in django template - exactly in layout.html

I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not. I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like,…
andilabs
  • 22,159
  • 14
  • 114
  • 151
40
votes
7 answers

Get absolute path of django app

I am writing a unit test that needs to access an image file that I put in "fixtures" directory right under my django app directory. I want to open up this image file in my test using relative path, which would require me to get the absolute path of…
tamakisquare
  • 16,659
  • 26
  • 88
  • 129
40
votes
4 answers

Django setting : psycopg2.OperationalError: FATAL: Peer authentication failed for user "indivo"

I am getting problem in Django project setting with POSTGRESQL. Here is my setting.py database setting DATABASES = { 'default':{ 'ENGINE':'django.db.backends.postgresql_psycopg2', # '.postgresql_psycopg2', '.mysql', or '.oracle' …
masterofdestiny
  • 2,751
  • 11
  • 28
  • 40
40
votes
4 answers

Python/Django - Avoid saving passwords in source code

I use Python and Django to create web applications, which we store in source control. The way Django is normally set up, the passwords are in plain text within the settings.py file. Storing my password in plain text would open me up to a number of…
Ashwin Balamohan
  • 3,303
  • 2
  • 25
  • 47
39
votes
8 answers

how can I check database connection to mysql in django

how can I do it? I thought, I can read something from database, but it looks too much, is there something like?: settings.DATABASES['default'].check_connection()
doniyor
  • 36,596
  • 57
  • 175
  • 260
38
votes
5 answers

How to define a default value for a custom Django setting

The Django documentation mentions that you can add your own settings to django.conf.settings. So if my project's settings.py defines APPLES = 1 I can access that with settings.APPLES in my apps in that project. But if my settings.py doesn't define…
sth
  • 222,467
  • 53
  • 283
  • 367
34
votes
1 answer

Specify Django Test Database names in settings.py

I'm specifying the databases using a python object: DATABASES = { 'default':{ 'ENGINE':'mysql', 'NAME':'testsqldb', 'USER':'', 'PASSWORD':'', }, 'dynamic_data':{ 'ENGINE': 'sqlite3', 'NAME':'', …
Michael Merchant
  • 1,509
  • 2
  • 17
  • 28
32
votes
2 answers

What is "swappable" in model meta for?

Looking tough django auth models code, I came across this bit of code: class User(AbstractUser): class Meta(AbstractUser.Meta): swappable = 'AUTH_USER_MODEL' It's obvious that it has something to do with the new AUTH_USER_MODEL setting…
frnhr
  • 12,354
  • 9
  • 63
  • 90
1
2
3
61 62