django具体如何引用放进static中的dist
时间: 2023-04-04 17:00:37 浏览: 61
您可以在 Django 的 settings.py 文件中设置 STATICFILES_DIRS 变量,将您的 dist 文件夹路径添加到其中。然后在您的 HTML 文件中使用 {% static %} 模板标签来引用您的静态文件。例如:{% static 'dist/js/main.js' %}。这将会将您的 main.js 文件从 dist 文件夹中引用到您的 HTML 文件中。
相关问题
django具体如何引用放进static中的dist,举个
例子说明一下?
您可以在 Django 的 settings.py 文件中设置 STATICFILES_DIRS 变量,将您的 dist 文件夹路径添加到其中。然后在您的 HTML 模板中使用 {% static 'dist/your_file.js' %} 的语法来引用您的静态文件。例如:
```python
# settings.py
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/dist'),
]
# template.html
<script src="{% static 'dist/your_file.js' %}"></script>
```
Django 不同app的static
文件如何设置?
在Django中,每个app都有自己的静态文件目录。在app的目录下创建一个名为“static”的目录即可。然后,您可以在app的任何地方使用静态文件。
例如,在您的app的views.py文件中,您可以使用以下代码来使用您的静态文件:
```
from django.shortcuts import render
def your_view(request):
return render(request, 'template.html')
```
然后,在您的模板(template.html)中,您可以使用以下代码来访问静态文件:
```
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="{% static 'yourapp/style.css' %}">
</head>
<body>
<!-- Your HTML code here -->
</body>
</html>
```
请注意,您需要在模板中使用{% load static %}指令来加载静态文件标签。然后,您可以使用{% static 'yourapp/style.css' %}标签来指定相对于app的静态文件路径。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)