Django static file configuration

Time:2021-8-30

Django static file configuration

1、 What is a static file

The files used by the website that have been written in advance are called static files

What are the static files?

① CSS file

②   JS file

③   Third party component: bootstrap

               sweetalert

               fontawesome

               …

 

  The HTML files used in the project are uniformly placed in the Templates folder;

You should also find a separate folder to store the static files used by the website. This folder is called static by default. This folder needs to be created manually

 

The folder is usually structured as follows:

- static
    - css
        All CSS files used by the website
    - js
        All JS files used by the website
    - image
        All photo files used by the website
    -Third party documents

 

 

2、 Static file configuration (realizing dynamic binding of static files)

Django static configuration file exposes the configuration information of the configuration file. You only need to write according to the fixed writing method to expose the corresponding static file resources. You can access the static file through the URL. CSS and JS files can play their role only when the static file is exposed

 

Add at the end of settings:

STATICFILES_DIRS = [
    os.path.join(BASE_ Dir, 'static') # the static here is the folder path
]

# STATIC_ Url = '/ xxx /' # accesses the interface prefix of back-end static resources. By default, the interface prefix is consistent with the static file name
"""

If you want to access the back-end static resources, you must start with the interface prefix followed by the specific file path to access the corresponding resources

When your interface prefix is correct, you will take the following path to each folder in the following list to find the corresponding resources
The sequence is from top to bottom. If no error is found, it will be reported
"""

 

Question: if the interface of static resources is modified many times, the imported path in the HTML file also needs to be modified manually. How to implement dynamic binding?

resolvent:

In the HTML page, you can modify the link and script tags in the head

{% load static %}

Recommended Today

Dynamic expansion of SCST shared disk

SCST shared disks support online capacity expansion. The operation is as follows: SCST server First, there is a ZFS storage volume, and now its capacity is expanded from 15g to 20g. zfs set volsize=20G tank/vol Modify the size attribute of device in SCST scstadmin -set_dev_attr device1 -attributes size=21474836480 -noprompt ISCSI client Rescan target iscsiadm -m […]