Django Settings
Django Settings.py file
As the setting is the most important feature of a phone with the help of which we can control our device and make changes to it. similarly, the settings.py file is one of the most important files of a Django project. The settings.py file contains all the configurations of our Django project. Here, we have covered all important points related to Django settings.py file.
- BASE_DIR - BASE_DIR is our Django project directory. It is the same directory where our manage.py is located. All the paths we define in our project relate to BASE_DIR.
- SECRET_KEY - The Django SECRET_KEY IS used in things like session management, signing data, password hashing, etc. we have to keep this key secure from others because if someone has this key they would be able to modify the cookies sent by our application.
- DEBUG - If we are writing programs or doing any development work its obvious that we will get some errors. Django provides an in-built debugger to solve these errors. We can use this debugger by using DEBUG = TRUE. In production DEBUG = False is preferred because we don’t want to show users why they are getting the error
- ALLOWED_HOSTS - It is the list of strings representing the domain names allowed to serve our website.
- INSTALLED_APPS - This section is used to store installed apps that are used in our project. There is a total of six built-in installed apps in the settings.py file.
- MIDDLEWARE - In Django, a middleware is a regular python class used to perform any function in our web application. These classes hold pieces of code that are processed upon every response our Django application gets. In the MIDDLEWARE section, we store all the middleware that is used in our project.
- ROOT_URLCONF - It tells Django about which Python module should be used as the URLconf for our Web application.
- TEMPLATES - In settings.py TEMPLATES is a list of all configurations. All the settings related to the template are stored in this section.
- WSGI_APPLICATION - WSGI stands for “web server gateway interface”. It is used to forward requests from the web server to the backend of the website. It is the starting point of our Django project. Any server you set up has to know where your WSGI application is.
- DATABASES - it is a directory containing all settings of our database. There are many databases like PostgreSQL, MariaDB, MySQL, Oracle, SQLite, etc. which are officially supported by Django. By default, Django uses the SQLite database. There are some more options like ENGINE, NAME, HOST, PORT, PASSWORD, etc. for more advanced configurations.
- AUTH_PASSWORD_VALIDATORS - In this section settings about password validators is stored. This setting is used to throw the validation error if the user entered a password that does not meet any requirement like minimum length, numeric password, etc.
- LANGUAGE_CODE - In this section, you can declare your website’s language code.
- TIME_ZONE - In this section, you can declare which time zone your website is using.
- STATIC_URL - It is a relative path to BASE_DIR. It is used to store the URL locations of our static files. This section tells Django where to look for static files.
- STATIC_ROOT - this section defines a single folder that collects all of your static files.