Python - Django - Static related files

Static files path set in settings.py

If the path is changed, then, html relevant route should be modified

CSS:

<link href="/static/dashboard.css" rel="stylesheet">

可以写成:

{% load static %}
<link href="{% static "dashboard.css" %}" rel="stylesheet">

或者:

{% load static %}
<link href="{% get_static_prefix %}dashboard.css" rel="stylesheet">

JS:

<script src="/static/js/myjs.js"></script>

可以写成:

{% load static %}
<script src="{% static "/js/myjs.js" %}"></script>

或者:

{% load static %}
<script src="{% get_static_prefix %}js/myjs.js"></script>

If a file is used multiple times multiple, you can give it a nickname

{% load static %}
{% static "/js/myjs.js" as myjs %}
<script src="{{ myjs }}"></script>

 

Guess you like

Origin www.cnblogs.com/sch01ar/p/11265948.html
Recommended