Appendix D. Settings

Your Django settings file contains all the configuration of your Django installation. This appendix explains how settings work and which settings are available.

What's a settings file?

A settings file is just a Python module with module-level variables. Here are a couple of example settings:

ALLOWED_HOSTS = ['www.example.com'] DEBUG = False DEFAULT_FROM_EMAIL = 'webmaster@example.com' 

Note

If you set DEBUG to False, you also need to properly set the ALLOWED_HOSTS setting.

Because a settings file is a Python module, the following apply:

  • It doesn't allow for Python syntax errors
  • It can assign settings dynamically using normal Python syntax, for example:
            MY_SETTING = [str(i) for i in range(30)] 
    
  • It can import values from other settings ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.