在每个django项目中,在其他项目之前需要的工具
django-before的Python项目详细描述
django before-每个django项目中任何其他项目之前都需要的工具。
子页面
制作子页面工具来计算根目录的相对路径。
# at the beginning of settings.pyfromdjango_beforeimportmake_subpather# e.g. I have project structure where this file is here: project_root/src/django_project/settings/base.py# so root of my project is 4 levels higher:subroot=make_subpather(__file__,4)# know I can handy get paths relative to root of the project:MEDIA_ROOT=subroot('static_content/media/')DIR_SAMPLE_IMAGES=subroot('src/crm/res/sample_images')
JSON设置读取器
make_json_settings_reader-从json文件读取设置的工具(例如秘密设置)。
# create settings readersecrets=make_json_settings_reader(subroot('conf/secrets.json'))# use it for reading settingsDATABASES={'default':{'ENGINE':'django.db.backends.postgresql_psycopg2','NAME':'mydbname','USER':'mydbuser','PASSWORD':secrets['DATABASE_PASSWORD'],}}SECRET_KEY=secrets['SECRET_KEY']
json文件中的数据必须表示为dict:
{"SECRET_KEY":"user123","DATABASE_PASSWORD":"user123"}