The difference between Django Static_url static_root staticfiles_dirs

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.