1

I have tried almost every Solution related to this but I am still unable to figure out why Bootstrap Modals are not working with me.

Whenever I click on the "button", the modal doesn't load.

This is my base.html file where I have included the dependencies.

{% load static %}
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <title>Website</title>


    


<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" >
<link href="{% static 'css/main.css' %}" rel="stylesheet" >
<link href="{% static 'css/fontawesome.min.css' %}" rel="stylesheet" >
<link href="{% static 'css/all.min.css' %}" rel="stylesheet" >



    <style>
     
    </style>

    
    <!-- Custom styles for this template -->
    <link href="{% static 'css/dashboard.css' %}" rel="stylesheet">
  </head>
  <body>
    
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3 fs-6" href="#">Website</a>
  <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="navbar-nav">
    <div class="nav-item text-nowrap">
      
    </div>
    
  </div>
  <img class="img-profile rounded-circle" src="{{request.user.account.profile_pic.url}}">
    <span class = "nav_user">Hello {{request.user.account.name}} </span>
    <span><a class="nav-link px-3 nav_user" href="{% url 'logout' %}">Sign out</a></span>
</header>

<div class="container-fluid">
  <div class="row">
    {% include 'partials/_sidebar.html' %}

    <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
      {% block content %}
      
      {% endblock  %}
    </main>
  </div>
</div>

 <!-- Bootstrap JS -->
 <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
 <!-- Jquery -->
 <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
 
    <script src="{% static 'js/main.js' %}" ></script>
   

  </body>
</html>

This is my Dashboard.html where I have made a sample Modal Button and also the modal, but when I click on the Button, Modal doesn't pop up,

{% extends 'base.html' %}

{% block content %}
    
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-3">
                <div class="card text-center">
                    <div class="card-header bg-danger text-white">
                        <div class="row align-items-center">
                            
                            <div class="col">
                                <h3 class="display-3"># {{player_rank}}</h3>
                                <h6>Rank</h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <h5>
                            <a class = "text-primary" href=""></a>
                        </h5>
                    </div>
                </div>
            </div>

            <div class="col-md-3">
                <div class="card text-center">
                    <div class="card-header bg-success text-white">
                        <div class="row align-items-center">
                            
                            <div class="col">
                                <h3 class="display-3">{{player.ratings}}</h3>
                                <h6>Ratings</h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <h5>
                            <a class = "text-primary" href=""></a>
                        </h5>
                    </div>
                </div>
            </div>

            <div class="col-md-3">
                <div class="card text-center">
                    <div class="card-header bg-primary text-white">
                        <div class="row align-items-center">
                            
                            <div class="col">
                                <h3 class="display-3">{{matches_played}}</h3>
                                <h6>Matches Played</h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <h5>
                            <a class = "text-primary" href=""></a>
                        </h5>
                    </div>
                </div>
            </div>

            <div class="col-md-3">
                <div class="card text-center">
                    <div class="card-header bg-info text-white">
                        <div class="row align-items-center">
                            
                            <div class="col">
                                <h3 class="display-3">{{matches_won}}</h3>
                                <h6>Matches Won</h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <h5>
                            <a class = "text-primary" href=""></a>
                        </h5>
                    </div>
                </div>
            </div>
        </div>

        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
            Launch demo modal
          </button>
          
          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  ...
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                  <button type="button" class="btn btn-primary">Save changes</button>
                </div>
              </div>
            </div>
          </div>
    </div> 

{% endblock %}

Can anyone tell me what's really the issue here? Am I missing some library or there is some other problem

Asad Hussain
  • 564
  • 2
  • 15

1 Answers1

-1

As I can see from your code, you're integrating Bootstrap v5.

With v5.0 of Bootstrap they dropped the dependency of jQuery, if I'm not totally wrong. Make sure to use the right syntax. They changed some parts for the modals, e.g. data-toggle="modal".

Bootstrap v5 Modal: https://getbootstrap.com/docs/5.0/components/modal/

First time I write something here, sorry for just some plain text.

Hyouka
  • 1
  • 1
  • I copied the Modal from the link you have provided, but it still is not working unfortuately. I also removed the JQuery Dependency but still nothing. – Asad Hussain Aug 08 '22 at 15:11