开发者

How do I get js and css to display in Django?

I've got a template, a.html, which looks like this:

<script type="text/javascript" src="jquery-1.4.min.js"></script>
<script type="text/j开发者_开发问答avascript" src="reg.js"></script>

Why doesn't this work?


Try:

<script type="text/javascript" src="{{ MEDIA_URL }}jquery-1.4.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}reg.js"></script>

You'll need to make sure you're serving static files correctly, and you'll need "django.core.context_processors.media" in the TEMPLATE_CONTEXT_PROCESSORS setting.


Because you didn't set up your web server to alias those to their corresponding static media.


Since your URLs can have arbitrary path depths, you need to get absolute path to your JS. e.g.

<script type="text/javascript" src="/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="/js/reg.js"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜