Django staticfiles app static file handling/reference

created at 07-17-2021 views: 4

In the use of django development, it is inevitable that you will always encounter the processing of static files. Especially for the front-end, the debugging of the page depends on static files (JS, CSS, Image, etc.)

File classification

Django divides static files into two categories: static and media. Django distinguishes them according to whether they interact with users:

  1. static: The application page needs (JS, CSS, Image...), these are relatively provided to the user, that is, these files (not strictly speaking) have no interaction with the user, and the developer generates these files to serve the users. , The user just simply enjoys the application service.
  2. media: files that the user interacts with the application (files uploaded by the user, etc.)

Static file settings

  • STATIC_ROOT
  • STATIC_URL
  • STATICFILES_DIRS
  • STATICFILES_STORAGE
  • STATICFILES_FINDERS

Static file reference

setting.py

STATIC_URL ='/static/'

# Folder to store static files
STATICFILES_DIRS = (
     os.path.join(BASE_DIR,'static'),
)

xx.html

<link rel="stylesheet" href="{% static '/admin.css' %}" media="all">
Please log in to leave a comment.