A Brief Introduction to the Python Django framework dj-scaffold Project
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
Since Django does not specify the directory structure specification for a project like rails, many people are confused about how the directory structure of the django project should be organized. 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.
?
1 2 |
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:
?
1 |
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.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Dj-scaffold.py projectname | + Docs/# documents used to store Projects | + 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 dependent on some projects. 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:
?
1 2 3 4 5 6 7 8 9 10 11 12 |
| + 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 # app's own settings file |-Tests. py |-Urls. py # urls configuration file '-Views. py |