Django_load settings configuration

When the django service is started using the following command, the setting will be automatically loaded

python manage.py runserver

By looking at manage.py you can find the loading code as

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings的路径id')

After knowing the principle of settings loading, you can directly load the settings configuration without starting the http service during debugging.

import os
import django
from dailyfresh import settings

# 导入配置django配置文件
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dailyfresh.settings')
django.setup()

print(settings.DATABASES)


Source code and other data acquisition methods

 Friends who want to get the source code, please like + comment + favorite , triple!

After three times in a row , I will send you private messages one by one in the comment area~

Guess you like

Origin blog.csdn.net/GDYY3721/article/details/131660567