No se puede cerrar el mensaje Flash en Django -- python campo con django camp Relacionados El problema

Unable to close flash message in Django


-1
vote

problema

Español

Estoy desarrollando una aplicación de muestra con Python y Django Framework. En esto, he mostrado un mensaje de flash con Cancelar [ x ]] para cerrar el mensaje usando django Mensajes Mensajes Framework en index.html usando base.html como (herencia de la plantilla) .

problema: El problema es aunque puedo mostrar el mensaje en index.html, pero no puedo cancelar . A continuación se muestran los archivos de código

base.html

  <!doctype html> <html lang="en">   <head>     <!-- Required meta tags -->     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1">      <!-- Bootstrap CSS -->     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">      <title>{% block title %}{% endblock title %} Harry Ice Creams</title>   </head>   <body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">     <div class="container-fluid">         <a class="navbar-brand" href="#">Harry Ice Creams</a>         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">         <span class="navbar-toggler-icon"></span>         </button>         <div class="collapse navbar-collapse" id="navbarSupportedContent">         <ul class="navbar-nav me-auto mb-2 mb-lg-0">             <li class="nav-item">             <a class="nav-link active" aria-current="page" href="/">Home</a>             </li>             <li class="nav-item">             <a class="nav-link" href="/about">About Us</a>             </li>             <li class="nav-item dropdown">             <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">                 Services             </a>             <ul class="dropdown-menu" aria-labelledby="navbarDropdown">                 <li><a class="dropdown-item" href="/services">Ice Cream</a></li>                 <li><a class="dropdown-item" href="#">Waffle</a></li>                 <li><hr class="dropdown-divider"></li>                 <li><a class="dropdown-item" href="#">Shake</a></li>             </ul>             </li>             <li class="nav-item">             <a class="nav-link" href="/contact">Contact Us</a>             </li>         </ul>         <form class="d-flex">             <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">             <button class="btn btn-outline-success" type="submit">Search</button>         </form>         </div>     </div> </nav>  // -----------------------FLASH MESSAGE CODE BELOW-----------------------------  {% if messages %}     {% for message in messages %} <div class="alert alert-{{ message.tags }} alert-dismissible fade show my-0" role="alert">   {{ message }}   <button type="button" class="close" data-dismiss="alert" aria-label="Close">     <span aria-hidden="true">&times;</span>   </button>       {% endfor %}   {% endif %} </div>  {% block body %}{% endblock body %}      <!-- Optional JavaScript; choose one of the two! -->      <!-- Option 1: Bootstrap Bundle with Popper -->     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>      <!-- Option 2: Separate Popper and Bootstrap JS -->     <!--     <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>     -->   </body> </html>    

index.html

  {% extends 'base.html' %} {% block title %}Home{% endblock title %} {% block body %} <div class="container-fluid my-4 px-0"> <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">   <ol class="carousel-indicators">     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active"></li>     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1"></li>     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2"></li>   </ol>   <div class="carousel-inner">     <div class="carousel-item active">       {% comment %} <img src="https://source.unsplash.com/1600x600/?icecream" class="d-block w-100" alt="..."> {% endcomment %}         <img src="/static/img/1.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Chocolate Cookie Dough</h5>         <p>This is warm treat cookies ice cream - vanilla. It's the perfect mixture of two desserts that customers already love. </p>       </div>     </div>     <div class="carousel-item">       {% comment %} <img src="https://source.unsplash.com/1600x600/?icecreams" class="d-block w-100" alt="..."> {% endcomment %}       <img src="/static/img/2.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Moose Tracks</h5>         <p>This fun treat has a lot of chunks! It's vanilla ice cream, peanut butter cups, and fudge. It's a new perspective for vanilla ice cream.</p>       </div>     </div>     <div class="carousel-item">       {% comment %} <img src="https://source.unsplash.com/1600x600/?cakes" class="d-block w-100" alt="..."> {% endcomment %}       <img src="/static/img/3.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Chocolate Frosted Doughnut</h5>         <p>Covered with chocolate layer and sprinkles, this doughnut is definitely for chocolate lovers.</p>       </div>     </div>   </div>   <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-bs-slide="prev">     <span class="carousel-control-prev-icon" aria-hidden="true"></span>     <span class="visually-hidden">Previous</span>   </a>   <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-bs-slide="next">     <span class="carousel-control-next-icon" aria-hidden="true"></span>     <span class="visually-hidden">Next</span>   </a> </div> </div>  <div class="container my-3"> <h1 class="my-4 text-center">Select from our range of Ice Creams</h1>       <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/4.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/5.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/6.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>          <div class="col">           <div class="card shadow-sm">             <img src="/static/img/7.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/8.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/9.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>          <div class="col">           <div class="card shadow-sm">             <img src="/static/img/10.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">            <img src="/static/img/11.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/12.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>       </div>     </div>  {% endblock body %}   

vers.py

  from django.shortcuts import render, HttpResponse from datetime import datetime from home.models import Contact from django.contrib import messages # Create your views here.   def index(request):     context = {         'variable': 'This is a TEST variable',         'name': 'MOHIT'     }     messages.success(request,'This is a test message')     return render(request, 'index.html', context)   def about(request):     return render(request, 'about.html')   def services(request):     return render(request, 'services.html')   def contact(request):     if request.method == 'POST':         name = request.POST.get('name')         email = request.POST.get('email')         phone = request.POST.get('phone')         desc = request.POST.get('desc')         contact = Contact(name=name, email=email, phone=phone,                           desc=desc, date=datetime.today())         contact.save()          # -------------------SENDING FLASH MESSAGE------------------------                  messages.success(request, 'Your message has been sent successfully.')     return render(request, 'contact.html')    

¿Alguna solución por favor?

Original en ingles

I am developing a sample application using python and Django framework . In this i have shown flash message with cancel [x] icon to close the message using Django Messages Framework in index.html using base.html as (template inheritance).

PROBLEM : The problem is although i am able to display the message in index.html , but i cannot cancel it. Below are the code files

base.html

<!doctype html> <html lang="en">   <head>     <!-- Required meta tags -->     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1">      <!-- Bootstrap CSS -->     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">      <title>{% block title %}{% endblock title %} Harry Ice Creams</title>   </head>   <body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">     <div class="container-fluid">         <a class="navbar-brand" href="#">Harry Ice Creams</a>         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">         <span class="navbar-toggler-icon"></span>         </button>         <div class="collapse navbar-collapse" id="navbarSupportedContent">         <ul class="navbar-nav me-auto mb-2 mb-lg-0">             <li class="nav-item">             <a class="nav-link active" aria-current="page" href="/">Home</a>             </li>             <li class="nav-item">             <a class="nav-link" href="/about">About Us</a>             </li>             <li class="nav-item dropdown">             <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">                 Services             </a>             <ul class="dropdown-menu" aria-labelledby="navbarDropdown">                 <li><a class="dropdown-item" href="/services">Ice Cream</a></li>                 <li><a class="dropdown-item" href="#">Waffle</a></li>                 <li><hr class="dropdown-divider"></li>                 <li><a class="dropdown-item" href="#">Shake</a></li>             </ul>             </li>             <li class="nav-item">             <a class="nav-link" href="/contact">Contact Us</a>             </li>         </ul>         <form class="d-flex">             <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">             <button class="btn btn-outline-success" type="submit">Search</button>         </form>         </div>     </div> </nav>  // -----------------------FLASH MESSAGE CODE BELOW-----------------------------  {% if messages %}     {% for message in messages %} <div class="alert alert-{{ message.tags }} alert-dismissible fade show my-0" role="alert">   {{ message }}   <button type="button" class="close" data-dismiss="alert" aria-label="Close">     <span aria-hidden="true">&times;</span>   </button>       {% endfor %}   {% endif %} </div>  {% block body %}{% endblock body %}      <!-- Optional JavaScript; choose one of the two! -->      <!-- Option 1: Bootstrap Bundle with Popper -->     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>      <!-- Option 2: Separate Popper and Bootstrap JS -->     <!--     <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>     -->   </body> </html>  

index.html

{% extends 'base.html' %} {% block title %}Home{% endblock title %} {% block body %} <div class="container-fluid my-4 px-0"> <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">   <ol class="carousel-indicators">     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active"></li>     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1"></li>     <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2"></li>   </ol>   <div class="carousel-inner">     <div class="carousel-item active">       {% comment %} <img src="https://source.unsplash.com/1600x600/?icecream" class="d-block w-100" alt="..."> {% endcomment %}         <img src="/static/img/1.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Chocolate Cookie Dough</h5>         <p>This is warm treat cookies ice cream - vanilla. It's the perfect mixture of two desserts that customers already love. </p>       </div>     </div>     <div class="carousel-item">       {% comment %} <img src="https://source.unsplash.com/1600x600/?icecreams" class="d-block w-100" alt="..."> {% endcomment %}       <img src="/static/img/2.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Moose Tracks</h5>         <p>This fun treat has a lot of chunks! It's vanilla ice cream, peanut butter cups, and fudge. It's a new perspective for vanilla ice cream.</p>       </div>     </div>     <div class="carousel-item">       {% comment %} <img src="https://source.unsplash.com/1600x600/?cakes" class="d-block w-100" alt="..."> {% endcomment %}       <img src="/static/img/3.jfif" class="d-block w-100" alt="...">       <div class="carousel-caption d-none d-md-block">         <h5>Chocolate Frosted Doughnut</h5>         <p>Covered with chocolate layer and sprinkles, this doughnut is definitely for chocolate lovers.</p>       </div>     </div>   </div>   <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-bs-slide="prev">     <span class="carousel-control-prev-icon" aria-hidden="true"></span>     <span class="visually-hidden">Previous</span>   </a>   <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-bs-slide="next">     <span class="carousel-control-next-icon" aria-hidden="true"></span>     <span class="visually-hidden">Next</span>   </a> </div> </div>  <div class="container my-3"> <h1 class="my-4 text-center">Select from our range of Ice Creams</h1>       <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/4.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/5.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/6.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>          <div class="col">           <div class="card shadow-sm">             <img src="/static/img/7.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/8.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/9.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>          <div class="col">           <div class="card shadow-sm">             <img src="/static/img/10.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">            <img src="/static/img/11.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>         <div class="col">           <div class="card shadow-sm">             <img src="/static/img/12.jfif" class="d-block w-100" alt="..." width="900" height="400">             <div class="card-body">               <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>               <div class="d-flex justify-content-between align-items-center">                 <div class="btn-group">                   <button type="button" class="btn btn-sm btn-outline-secondary">View</button>                   <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>                 </div>                 <small class="text-muted">9 mins</small>               </div>             </div>           </div>         </div>       </div>     </div>  {% endblock body %} 

views.py

from django.shortcuts import render, HttpResponse from datetime import datetime from home.models import Contact from django.contrib import messages # Create your views here.   def index(request):     context = {         'variable': 'This is a TEST variable',         'name': 'MOHIT'     }     messages.success(request,'This is a test message')     return render(request, 'index.html', context)   def about(request):     return render(request, 'about.html')   def services(request):     return render(request, 'services.html')   def contact(request):     if request.method == 'POST':         name = request.POST.get('name')         email = request.POST.get('email')         phone = request.POST.get('phone')         desc = request.POST.get('desc')         contact = Contact(name=name, email=email, phone=phone,                           desc=desc, date=datetime.today())         contact.save()          # -------------------SENDING FLASH MESSAGE------------------------                  messages.success(request, 'Your message has been sent successfully.')     return render(request, 'contact.html')  

any solution please ?

     

Lista de respuestas

0
 
vote

Llame a la Biblioteca JQery en su código.

 

Call the jQuery library in your code.

 
 

Relacionados problema

1  Subir archivos con Django-Perfiles  ( File upload with django profiles ) 
Estoy usando el paquete Django-Contib django-perfiles , y todo está funcionando bien, mi único problema es que me gustaría que el formulario cargar un archiv...

3  AppNames Unicode en Django  ( Unicode appnames in django ) 
Vivo en Noruega, y cuando hago a las aplicaciones de Django, me gustaría poder nombrar mis aplicaciones con personajes como "æøå", estos personajes funcionan ...

2  ¿Django tiene un caché basado en la memoria o tiene que usar Memcache?  ( Does django have a memory based cache or do you have to use memcache ) 
¿Puedo almacenar objetos en la memoria de los servidores a los datos de caché utilizando Django, o tengo que usar Memcache para eso? ...

3  Modificar la dirección en Django Middleware  ( Modify address in django middleware ) 
No sé si es posible, pero me gustaría agregar algunos parámetros al final de la URL utilizando Middleware. ¿Se puede hacer sin redireccionar después de la URL...

17  ¿Hay alguna lista de motores de blog, escrito en Django?  ( Is there any list of blog engines written in django ) 
¿Hay alguna lista de motores de blog, escrito en Django? ...

0  ¿Cuál es la mejor UI para seleccionar las etiquetas de una lista de las etiquetas existentes?  ( What is the best ui for selecting tags from a list of existing tags ) 
Estoy usando el marcado Django. Mi modelo simplemente contiene un campo con una lista de etiquetas separadas por comas. Me gustaría que el usuario pudiera sel...

0  ¿Pueden los usuarios que han usado Django y Ruby en los rieles dan una pequeña comparación de usarlos?  ( Can users who have used both django and ruby on rails give a little comparison o ) 
duplicado: Django o Ruby-On-Rails? He estado leyendo en Ruby On Rails, ¡y parece que en algunos hilos, algunos usuarios como Django también? ¿Puede ...

92  ¿Cómo sabe Django la orden de prestar campos de formulario?  ( How does django know the order to render form fields ) 
Si tengo un formulario de Django, como: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() se...

55  Vistas de clase en Django  ( Class views in django ) 
django Ver puntos a una función, lo que puede ser un problema si quieres cambiar solo un poco de funcionalidad. Sí, podría tener un millón de argumentos de ...

17  ¿Está exponiendo el token de protección de la sesión de una sesión segura?  ( Is exposing a sessions csrf protection token safe ) 
Django viene con protección middleware de protección CSRF , que Genera un token único por sesión para su uso en formularios. Scanse todas las solicitudes ent...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos