Static file-related operations involve:
A. File location and access path mapping
B. setting.py and static-related configurations
Static_url
Static_root
Staticfiles_dirs
C. How the static file is referenced in HTML
D. Python manage.py collectstatic
1. Development environment-directory structure
2. setting.py Settings
STATIC_URL = ‘/static/‘# STATIC_ROOT= os.path.join(BASE_DIR,‘static‘)STATICFILES_DIRS=( os.path.join(BASE_DIR,‘static‘),)
The actual access address for the browser is set in Static_url.
Staticfiles_dirs corresponding file path
3. Development environment-access testing
4. HTML reference (Django Jinja2 template) 4.1 Hard address to use directly
HTML Head Section
4.2 References using
5. On-Line deployment issuesWhen you need to deploy admin at the same time
Run command to collect static files Python manage.py collectstaticError at this time
Modify the setting.py fileSTATIC_URL = ‘/static/‘STATIC_ROOT= os.path.join(BASE_DIR,‘static‘)# STATICFILES_DIRS=(# os.path.join(BASE_DIR,‘static‘),# )
Run the Python manage.py collectstatic againAfter completion "Static_root" is the static directory, resulting in other items of the static folder (including content)
After the collection is complete, change back to config, comment out static_rootSTATIC_URL = ‘/static/‘# STATIC_ROOT= os.path.join(BASE_DIR,‘static‘)STATICFILES_DIRS=( os.path.join(BASE_DIR,‘static‘),)
The program is packaged, uploaded to the server, tested byPython Django Learning two: Static file processing and on-line deployment testing