- Django 2 by Example
- Antonio Melé
- 363字
- 2021-06-25 21:18:58
Project settings
Let's open the settings.py file and take a look at the configuration of our project. There are several settings that Django includes in this file, but these are only a part of all the Django settings available. You can see all settings and their default values in https://docs.djangoproject.com/en/2.0/ref/settings/.
The following settings are worth looking at:
- DEBUG is a boolean that turns the debug mode of the project on and off. If it is set to True, Django will display detailed error pages when an uncaught exception is thrown by your application. When you move to a production environment, remember that you have to set it to False. Never deploy a site into production with DEBUG turned on because you will expose sensitive project-related data.
- ALLOWED_HOSTS is not applied while debug mode is on, or when the tests are run. Once you move your site to production and set DEBUG to False, you will have to add your domain/host to this setting in order to allow it to serve your Django site.
- INSTALLED_APPS is a setting you will have to edit for all projects. This setting tells Django which applications are active for this site. By default, Django includes the following applications:
- django.contrib.admin: An administration site
- django.contrib.auth: An authentication framework
- django.contrib.contenttypes: A framework for handling content types
- django.contrib.sessions: A session framework
- django.contrib.messages: A messaging framework
- django.contrib.staticfiles: A framework for managing static files
- MIDDLEWARE is a list that contains middleware to be executed.
- ROOT_URLCONF indicates the Python module where the root URL patterns of your application are defined.
- DATABASES is a dictionary that contains the settings for all the databases to be used in the project. There must always be a default database. The default configuration uses an SQLite3 database.
- LANGUAGE_CODE defines the default language code for this Django site.
- USE_TZ tells Django to activate/deactivate timezone support. Django comes with support for timezone-aware datetime. This setting is set to True when you create a new project using the startproject management command.
Don't worry if you don't understand much about what you are seeing. You will learn the different Django settings in the following chapters.
推薦閱讀
- 物聯網標準化指南
- 自動駕駛網絡:自智時代的網絡架構
- Truffle Quick Start Guide
- 網絡故障現場處理實踐(第4版)
- Learning QGIS 2.0
- Oracle SOA Suite 11g Performance Tuning Cookbook
- 通信簡史:從信鴿到6G+
- 網絡安全技術與解決方案(修訂版)
- Building RESTful Web Services with Spring 5(Second Edition)
- IPv6網絡切片:使能千行百業新體驗
- 面向5G-Advanced的關鍵技術
- 6G:面向2030年的移動通信
- React Cookbook
- 物聯網工程概論
- 網絡利他行為研究:積極心理學的視角