Django:未加载静态文件 [英] Django : static files are not loaded

查看:140
本文介绍了Django:未加载静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试此页面中提到的代码: dynamic-formset.js 并且我添加了:

i'm trying to test the code mentionned in this page : dynamic-formset.js and i added :

<script src="{% static  'js/dynamic-formset.js' %}"></script>
<script src="{% static  'js/jquery-3.3.1.js' %}"></script>

以便加载包含js的静态文件. 然而,js不起作用,我在控制台中获得以下几行:

in order to load static files that contains js. howerver the js doesn't work and i'm getting in the console the following lines :

 "GET /static/js/dynamic-formset.js HTTP/1.1" 404 1777
 "GET /static/js/jquery-3.3.1.js HTTP/1.1" 404 1768

当我用https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js替换导入jquery的第二个ligne时,我没有得到:

when i replace the second ligne that imports jquery with the https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js , i dont get :

"GET /static/js/jquery-3.3.1.js HTTP/1.1" 404 1768

我只得到"GET /static/js/dynamic-formset.js HTTP/1.1" 404 1777

您知道为什么它不起作用吗?我猜静态文件没有加载. 有什么帮助吗?谢谢

do you have any idea why it doesn't work ? i guess that the static files are not loading. Any help please ? Thank You

推荐答案

如果您使用的是django 2.x.x,请确保您的静态文件位于与您的应用程序名称相对应的静态文件夹内的子文件夹中. 请参阅其他问题

If you are using django 2.x.x make sure your static files are in a sub folder inside the static folder that corresponds to your app name. See Other question

这篇关于Django:未加载静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆