浅谈Django如何加载JS和CSS
1.在settings.py 设置如下
1 | STATIC_URL = '/static/' |
在项目根目录下新建static文件夹,把JS和CSS文件放入static文件夹中。
2.在HTML文件中引入静态文件
1 | {% load staticfiles %} |
在HTML文件中引入JS和CSS
1 | <script src="{% static 'macarons.js' %}"></script> |
English Version
Introduction of JS and CSS Files into Django.
Step 1: Writting the following codes in the settings.py, which is located in /projectname/projectname/
1 | STATIC_URL = '/static/' |
Create a new folder named “static”, under the project root directory and put JS and CSS files into the static folder.
Step 2: importing the staticfiles to HTML files.
1 | {% load staticfiles %} |