Django 路径到 javascript 不起作用
我一直在尝试各种方法,但无法解决这个问题!
由于某种原因,在 Django 开发服务器上,JavaScript 的路径不起作用。
目录结构
site
|
appName static templates
| | |
views.py javascript appName
| |
script.js index.html
在我的index.html中
<script type="text/javascript" src=../../static/javascript/script.js></script>
,但它不起作用!
如果我将 script.js 直接复制并粘贴到 index.html 中,所有功能都可以工作,只是路径混乱了。
I've been trying all sorts of things and can't figure this out!
For some reason on the Django development server the paths to the JavaScript just don't work.
Directory structure is
site
|
appName static templates
| | |
views.py javascript appName
| |
script.js index.html
In index.html I have
<script type="text/javascript" src=../../static/javascript/script.js></script>
And it doesn't work!
If I copy and paste the script.js directly into index.html all of the functionality works, just the pathing is messed up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Django 默认不提供静态资源。可以让它做到这一点,仅在开发环境中 - 请参阅文档。
Django does not serve static assets by default. It is possible to make it do it, in the development environment only - see the documentation.
怎么样:
你能看到它正在 Firebug net 选项卡中加载吗?
How about:
Can you see it being loaded in Firebug net tab?
settings.py 中的 MEDIA 值是多少?我有以下内容,它们在开发服务器上运行良好:
项目结构:
在您的任何模板中:
What are your MEDIA values in settings.py? I have the following and they work fine on the dev server:
Project structure:
In any of your templates: