6👍
Only if you will parse JS like a template.
If you need some variable inside JS (like STATIC_URL
), it is ok to use
<script>window.staticUrl = "{{ STATIC_URL }}"</script>
or
<html data-static-url="{{ STATIC_URL }}">
in your base template
2👍
No, not if you include the application.js file as
<script src="application.js"></script>
The template loader form Django will just render this to the final output of the html code. The Django template tags/filters only render on template pages – they do not apply to external sources.
You could attempt to load the JavaScript file as text into the template. So instead of referencing an external file, you would basically “paste” the code from the file into the template.
- [Django]-Pass variable from middleware to templates
- [Django]-Can't get django urls to work
- [Django]-ManyToMany in Django admin: select none
- [Django]-Django ping google http error
- [Django]-Django custom templatetag not getting request in context
1👍
You can serve your javascript as dynamic page. Create new django view to serve it (or use django.views.simple.direct_to_template) and use template with your actual javascript content.
- [Django]-Django official tutorial for the absolute beginner, absolutely failed!
- [Django]-Django-like frameworks?