[Answered ]-External JS in Django apps best practice

2👍

Yes you can do it:

1. base.html

<html>
<head>
  <title>Foobar</title>
</head>
<body>
  {% block content %}{% endblock %}

  {% block js %}{% endblock %}
</body>
</html>

2. yourpage.html

{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
  <p>your content!</p>
{% endblock %}

{% block js %}
  <script src="{% static 'js/foobar.js' %}"></script>
{% endblock %}
👤binpy

Leave a comment