[Fixed]-Different static files in different templates

1πŸ‘

βœ…

When you extend a template you need to make sure all of the code in the child template is inside a block. So for your main template typically you do something like:

main.html

{% load staticfiles %} <!-- This should go at the top for readability -->

<!-- Load any site wide JS here -->
<script type="text/javascript" src="{% static 'main.js' %}"></script>

{% block js %}<!-- Put JS in here for extended templates -->{% endblock %}

detail.html

{% extends 'layout/main.html' %}
{% load staticfiles %}

{% block js %}
  <script type="text/javascript" src="{% static 'fancybox.js' %}"></script>
{% endblock %}

{% block title %}
<!-- SOME CONTENT -->
{% endblock %}

0πŸ‘

    {% extends 'layout/main.html' %}
  {% block title %}
    {% load staticfiles %}
        <script type="text/javascript" src="{% static 'fancybox.js' %}"></script>

  
    <!-- SOME CONTENT -->
    {% endblock %}

use this code in details.html.You have to put {% block body%}
at the top just after the extend or include statement

Leave a comment