Introduction to Staticfiles usage in Python under Django framework

Source: Internet
Author: User
django1.3 New added a app,django.contrib.staticfiles for static resource management. In previous versions of Django, the management of static resources has always been a problem. Some apps are released with a static resource file, and you must manually copy the static resource files from each app to the same static directory when you deploy them. After introducing Staticfiles, you only need to execute./manage.py collectstatic It is easy to copy the static resources used in the app to the same directory.

The introduction of Staticfiles facilitates the management of Django static files, but it feels like Staticfiles's documentation is not too clear, and it makes me confused when I first use it.

The following is a brief introduction to the main configuration of Staticfiles:

    • Static_root: The directory to which the static files will be copied after running manage.py collectstatic. Note: Do not put static files of your project into this directory. This directory is only used when running collectstatic. I took it for granted that this directory is the same as the media_root, resulting in the inability to find static files in the development environment.
    • Static_url: The starting URL of the static file set, which can only be referenced within the template. This parameter has the same meaning as Media_url.
    • Staticfiles_dirs: There are static file locations that need to be managed in addition to the static directory for each app, such as the project's common file-statically files. And the meaning of template_dirs is similar.
    • The static files in the static/directory under each app are automatically found in the Django Development server, which is similar to the Templates directory under the previous app.
    • Adding code for static file processing in urls.py
  From django.contrib.staticfiles.urls import staticfiles_urlpatterns  # ... the rest of your URLconf goes  here ... Urlpatterns + = Staticfiles_urlpatterns ()
  • 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.