Click here to Skip to main content
15,845,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All, I am trying to design a web application using Django. The application requires to use Materializecss, jQuery (DatePicker and Select2) and Datatables. My challenge is to include the necessary .css and .js files only once in base.html such that these libraries are cascaded in other pages as well. Any tips in including these files correctly would help a lot. Thanks.

What I have tried:

<!DOCTYPE html>
{% load static %}
    <!--Import Google Icon Font-->
    <link href="" rel="stylesheet">
    <!--Import materialize.css-->
    <link href=""
    <link href="" rel="stylesheet">
    <link href=""
    <script src="" defer></script>
    <!--Let browser know website is optimized for mobile-->
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <link href="{% static 'css/dashboard2.css' %}" rel="stylesheet">

{% include 'partials/sidenav.html' %}
{% include 'partials/navbar.html' %}
{% block content %}
{% endblock %}

<!--<script src=""></script>-->
<script src=""></script>
<script src=""></script>
    src="" type="text/javascript">
	// Code for SideNav

	// Code for DataTable
Updated 21-Nov-22 20:23pm

1 solution

It is only possible if base.html functioning as a base/master page - which is not supported in plain html, but supported in many development packages...
Like Django templating...

Django | Creating and Using MasterPages[^]
Share this answer
Member 15839423 22-Nov-22 1:56am    
Yes. That's what I am trying to achieve. Django template base.html, trying to use the partials concept. I am getting jQuery is not defined error.
Kornfeld Eliyahu Peter 22-Nov-22 2:25am    
Getting the error in the base.html? Maybe the order of your include is wrong?
On what line do you get the error?
Member 15839423 22-Nov-22 4:53am    
The Network tab shows the beloww:
( function( factory ) {
"use strict";

if ( typeof define === "function" && define.amd ) {

// AMD. Register as an anonymous module.
define( [ "jquery" ], factory );
} else {

// Browser globals
factory( jQuery );
} )( function( $ ) {
"use strict";
Member 15839423 22-Nov-22 4:58am    
Link to image:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900