This article briefly introduces the dj-scaffold project of the Python Django framework, which is used to assist in directory settings of the Django framework, for more information, see Django's failure to specify the directory structure specification of a project like rails. many people are confused about how to organize the directory structure of the django project. For this reason, I have created another open-source project dj-scaffold (django scaffolding ). This project is used to automatically generate a labeled django project and app.
Project address: https://github.com/vicalloy/dj-scaffold
Install
It has been released to pypi, so you can use pip or easy_install for installation.
pip install dj-scaffold easy_install dj-scaffold
Use
Dj-scaffold mainly provides two commands: dj-scaffold.py and lbstartapp.
Dj-scaffold.py
This script is used to replace the startproject command of django. The usage is as follows:
dj-scaffold.py projectname
After the command is executed, project projectname is created. The scripts create_env.py and env. rc are provided in the scripts directory of the project.
- Create_env.py execute this script to automatically initialize the python virtual environment. The new python virtual environment is in the env directory.
- Env. rc the script user starts the python virtual environment (source env. rc ). This script also sets the shortcut $ mg for python manage. py. You can call $ mg in any directory to execute the django command. For example, you use $ mg runserver to start the test server.
The directory structure of the project is as follows:
Note: There are too many files and some unimportant files are removed.
Dj-scaffold.py projectname | + docs/# documents used to store the project | + env/# python virtual environment, automatically generated by the script | ~ Requirements/# storage location of third-party dependent packages | '-requirements. pip # pip dependency description file | ~ Scripts/# system-related scripts |-create_env.py # Create a python virtual environment (env directory) | '-env. rc # enter the python virtual environment. Python manger. py shortcut $ mg is also provided. $ Mg can be used in any directory. | ~ Sites/# Django project file. Some default configurations are added to the settings file. If the database uses sqlite by default, set the project template and static file directory. | + Media/# static project files (uploaded by users) | + static/# static project files (css, js, etc) | '+ templates/# Project template | + tools/# third-party toolkit on which some projects depend. Such as the python virtual environment initialization script. '~ Wsgi/# wsgi file for project deployment '-dj_scaffold.wsgi
Lbstartapp
Lbstartapp is provided as an extension command of django. You can use this command after adding dj_scaffold to INSTALLED_APPS. This command will generate a standard app. compared with the startapp that comes with django, lbstartapp will also generate the default directories of apps that are not commonly used. The corresponding directory structure is as follows:
| + Management/# command directory | + static/# static file directory | + templates/# Template directory | + templatetags/# tag directory |-_ init __. py |-admin. py # The models configuration file of the admin management background |-forms. py |-models. py |-settings. py # settings file of the app |-tests. py |-urls. py # urls configuration file '-views. py