When using the Django framework, we often need to deal with static files, such as CSS style sheets, JavaScript scripts, and images. In this article, we will explore how to reference static files in Django.

When using the Django framework, we often need to deal with static files, such as CSS style sheets, JavaScript scripts, and images. In this article, we will explore how to reference static files in Django.

First, we need to create a directory in the Django project for storing static files. By default, Django looks in the project root for statica directory named . If the directory does not exist, you can create it manually.

Next, we can place the static files in staticthe directory and divide the folders according to our own organization. For example, we can staticcreate a csssubdirectory called under the directory and place all the CSS files in it.

In Django, you can use {% static %}template tags to reference static files. This template tag will generate the correct URL path based on the configuration of your static file directory. Here is an example of using {% static %}tags to reference a CSS file:

<link rel="stylesheet" type

Guess you like

Origin blog.csdn.net/qq_33885122/article/details/132806260