0

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/javascript" src="reg.js"></script>

Why doesn't this work?

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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>

1 Comment

Also, make sure you have those files setup at the said locations by adding something like (r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.CORE_MEDIA_ROOT}), On production, the main webserver (apache or nginx etc.) should serve the content instead of your django application. Re

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.