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
439
votes
17 answers

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

I have some stuff in settings.py that I'd like to be able to access from a template, but I can't figure out how to do it. I already tried {{CONSTANT_NAME}} but that doesn't seem to work. Is this possible?
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
191
votes
3 answers

How do I reference a Django settings variable in my models.py?

This is a very beginner question. But I'm stumped. How do I reference a Django settings variable in my model.py? NameError: name 'PRIVATE_DIR' is not defined Also tried a lot of other stuff including settings.PRIVATE_DIR settings.py: PRIVATE_DIR…
codingJoe
  • 4,713
  • 9
  • 47
  • 61
177
votes
13 answers

How to send email via Django?

In my settings.py, I have the following: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Host for sending e-mail. EMAIL_HOST = 'localhost' # Port for sending e-mail. EMAIL_PORT = 1025 # Optional SMTP authentication information…
Derek
  • 11,980
  • 26
  • 103
  • 162
161
votes
14 answers

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

I was trying to configure my Django project to deploy to Heroku. I am getting the following error and I don't really know how to fix it. Here is the full traceback and error: 22:46:15 web.1 | Traceback (most recent call last): 22:46:15 web.1 | …
ApathyBear
  • 9,057
  • 14
  • 56
  • 90
131
votes
2 answers

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

I'm reading up that most people do from django.conf import settings but I don't undertstand the difference to simply doing import settings in a django project file. Can anyone explain the difference?
tzenderman
  • 2,523
  • 3
  • 21
  • 24
116
votes
13 answers

How to set up a PostgreSQL database in Django

I'm new to Python and Django. I'm configuring a Django project using a PostgreSQL database engine backend, But I'm getting errors on each database operation. For example when I run manage.py syncdb, I'm getting: C:\xampp\htdocs\djangodir>python…
André
  • 24,706
  • 43
  • 121
  • 178
115
votes
10 answers

Where to store secret keys DJANGO

For the life of me, I have been looking for this everywhere and have not found the answer. I hope I am not posting a duplicate. It is advised everywhere that you should keep your secret keys in a separate file from your general settings.py. Also,…
nitochi
  • 1,285
  • 2
  • 11
  • 12
113
votes
6 answers

How to set up custom middleware in Django?

I'm trying to create a middleware to optionally pass a kwarg to every view that meets a condition. The problem is that I cannot find an example of how to set up the middleware. I have seen classes that override the method I want to,…
Atma
  • 29,141
  • 56
  • 198
  • 299
103
votes
1 answer

Is there any difference between django.conf.settings and import settings?

What is the basic difference between the following import statements in a Django app? import settings and from django.conf import settings
Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
102
votes
2 answers

Simple Log to File example for django 1.3+

The release notes say: Django 1.3 adds framework-level support for Python’s logging module. That's nice. I'd like to take advantage of that. Unfortunately the documentation doesn't hand it all to me on a silver platter in the form of complete…
John Mee
  • 50,179
  • 34
  • 152
  • 186
99
votes
32 answers

model not showing up in django admin

I have ceated several django apps and stuffs for my own fun and so far everything has been working fine. Now I just created new project (django 1.2.1) and have run into trouble from 1st moments. I created new app - game and new model Game. I created…
Odif Yltsaeb
  • 5,575
  • 12
  • 49
  • 80
97
votes
6 answers

How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?

I'm configuring a Django project that were using the server filesystem for storing the apps static files (STATIC_ROOT) and user uploaded files (MEDIA_ROOT). I need now to host all that content on Amazon's S3, so I have created a bucket for this.…
70
votes
8 answers

Django - after login, redirect user to his custom page --> mysite.com/username

By default after login django redirects the user to an accounts/profile page or if you edit the LOGIN_REDIRECT_URL you can send the user to another page you specify in the settings.py. This is great but I would like the user (after login) to be…
avatar
  • 12,087
  • 17
  • 66
  • 82
69
votes
6 answers

Why is Django throwing error "DisallowedHost at /"?

I am setting up my own Django server using this Digital Ocean tutorial. I created the Django framework following each step, and ran the server using this command: ./manage.py runserver 0.0.0.0:8000 When I tried to visit the IP at port 8000, the…
alukin
  • 803
  • 1
  • 7
  • 6
68
votes
5 answers

Is there a function for generating settings.SECRET_KEY in django?

I wrote an ansible-role for openwisp2 to ease its deployment, it's a series of django apps. To ease the deployment as much as possible, I wrote a simple (probably trivial) SECRET_KEY generator script which is called by ansible to generate the secret…
nemesisdesign
  • 8,159
  • 12
  • 58
  • 97
1
2 3
61 62