# URL address when providing Web access Static_url = '/static/' # is used to copy files from all folders in all staticfiles_dirs and files in each app's static directory, For ease of deployment Static_root = Os.path.join (Base_dir, ' static ') # All folders with static files Staticfiles_dirs = ('/usr/local/lib/python3.4/ Dist-packages/django/contrib/admin/static ',)
When Django shuts down debug mode, it is the production environment. Django official says that if the Django framework is a production environment, its static file provider should not go away from the Django framework, and it must deploy Nginx or other Web servers on the front of the Django framework to provide static access to the portal, the first to push Nginx.
The Nginx configuration is as follows:
server { listen 80; server_name 127.0.0.1 charset UTF-8; access_log /var/log/nginx/django_pro01_access.log; error_log /var/log/nginx/django_pro01_ error.log; client_max_body_size 75m; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8000; uwsgi_read_timeout 2; } location /static { # Here do a visit static directory not go uwsgi expires 30d; autoindex on; add_header cache-control private; alias /usr/share/nginx/django_pro01/static/; } }
In Nginx, you need to do a separate route to access the/static/directory.
All static files should be obtained from the directory "/usr/share/nginx/django_pro01/static/" (that is, the static_root defined above).
Run Python manage.py collectstatic
The purpose of this command is to static_root the static directory defined in the development pattern, and to provide "/static" (Static_url) as the access URL in the Unified directory:
1. Start by copying static files such as JSS and CSS from the admin admin background to the Static_root directory in the configuration file from the Django expansion pack.
2. Then copy the contents of all directories in the Staticfiles_dirs list to the Static_root directory
The difference between Django Static_url static_root staticfiles_dirs