Python Django Learning two: Static file processing and on-line deployment testing

Source: Internet
Author: User

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 issues

When you need to deploy admin at the same time

Run command to collect static files Python manage.py collectstatic

Error at this time

Modify the setting.py file
STATIC_URL = ‘/static/‘STATIC_ROOT= os.path.join(BASE_DIR,‘static‘)# STATICFILES_DIRS=(#     os.path.join(BASE_DIR,‘static‘),# )
Run the Python manage.py collectstatic again

After 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_root
STATIC_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 by

Python Django Learning two: Static file processing and on-line deployment testing

Related Article

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.