Reverse for 'company_delete' with arguments '('',)' not found. 1 pattern(s) tried: ['company/(?P<pk>\\d+)/delete/$'] - django

I am getting:
django.urls.exceptions.NoReverseMatch: Reverse for 'company_delete' with arguments '('',)' not found. 1 pattern(s) tried: ['company/(?P\d+)/delete/$']
and in my console it is showing:
- Failed to load resource: the server responded with a status of 500 (Internal Server Error)
My views.py
def company_delete(request,pk):
data = dict()
company = get_object_or_404(Company,pk=pk)
if request.method == "POST":
company.delete()
data['form_is_valid'] = True
companies = Company.objects.all()
data['company_list'] = render_to_string('company_list_2.html',{'companies': companies})
else:
context = {'company': company}
data['html_form'] = render_to_string('company_delete.html',context,request=request)
return JsonResponse(data)
my urls.py
urlpatterns = [
url(r'^company/$', views.company_list, name='company_list'),
url(r'^company/create/$', views.company_create, name='company_create'),
url(r'^company/(?P<pk>\d+)/update/$', views.company_update, name='company_update'),
url(r'^company/(?P<pk>\d+)/delete/$', views.company_delete, name='company_delete'),
]
my company_list_2.html
{% for c in companies %}
<tr>
<td>{{ c.name }}</td>
<td>{{ c.description }}</td>
<td>{{ c.website }}</td>
<td>{{ c.address }}</td>
<td>{{ c.phone }}</td>
<td>{{ c.email }}</td>
<td>{{ c.contact }}</td>
<td>
<button class="btn btn-warning show-form-update" data-url="{% url 'company_update' c.pk %}">
<span class="glyphicon glyphicon-pencil"></span>
Edit
</button>
</td>
<td>
<button class="btn btn-danger show-form-delete" data-url="{% url 'company_delete' c.pk %}">
<span class="glyphicon glyphicon-trash"></span>
Delete
</button>
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="text-center bg-warning">No Company</td>
</tr>
{% endfor %}
my company_delete.html
{% load crispy_forms_tags %}
<form method="post" data-url="{% url 'company_delete' c.pk %}" class="delete-form">
{% csrf_token %}
<div class="modal-header">
<h3 class="modal-title" >Delete Company</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="lead"> Are you sure you want to delete this company <strong>{{ c.name }}</strong></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete Company</button>
</div>
</form>

As say #Ivan Starostin just put company.pk instance c.pk in your url form
<form method="post" data-url="{% url 'company_delete' company.pk %}" class="delete-form">
...
</form>

Related

Django delete record using modal

I'm new in Django and i like to implement a Modal to delete records. The problem is a funny error in the modal form because is expecting a parameter. The modal link has this
but I don't know how add the right parameter.
This is my List in html
<table id="tablaAlmacenes" class="table table-bordered table-striped">
<thead>
<tr>
<th>Almacén</th>
<th>Detalles</th>
<th></th>
</tr>
</thead>
<tbody>
{% for almacen in object_list %}
<tr>
<td>{{ almacen.almacen }}</td>
<td>{{ almacen.descripcion }}</td>
<td>
<div>
Detalles
<a a href="" class="btn btn-link text-primary">Editar</a>
<a class="btn btn-link deleteAlmacen" data-id="{{ almacen.id}}"><span class="fas fa-trash text-danger"></a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Almacén</th>
<th>Detalles</th>
<th></th>
</tr>
</tfoot>
</table>
this is my url.py
urlpatterns = [
path('',include('polls.urls'),name='home'),
path('admin/', admin.site.urls),
# path('contact/',views.contact, name='contacto')
path('almacenes/', AlmacenesListView.as_view(), name='almacenes'),
path('almacenes/nuevo', AlmacenesCreateView.as_view(), name='crear_almacen'),
path('almacenes/<int:id>/remove/', AlmacenesDeleteView.as_view(), name='eliminar_almacen')
]
This is my views.py
class AlmacenesListView(ListView):
model = Almacen
template_name = 'pages/index.html'
success_message = "Bien!!!!"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = "Lista de Almacenes"
print(reverse_lazy('almacenes'))
return context
class AlmacenesCreateView(SuccessMessageMixin, CreateView):
model = Almacen
form_class = AlmacenesForm
success_url = reverse_lazy('almacenes')
success_message = "Bien!!!!"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
class AlmacenesDeleteView(DeleteView):
model = Almacen
success_url = reverse_lazy('almacenes')
and my modal code
<div class="modal fade" aria-modal="false" id="deleteAlmacenModal">
<div class="modal-dialog modal-dialog-centered modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirmación</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>¿Desea eliminar el Almacen?</p>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<form action="{% url 'eliminar_almacen' (some parameter here but error) %}" method="POST">
{% csrf_token %}
<input type="hidden" name="id" id="almacen_id"/>
<button type="submit" class="btn btn-danger">Eliminar</button>
</form>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
scrpt for modal
$(document).on('click','.deleteAlmacen',function(){
var id_almacen=$(this).attr('data-id');
$('#almacen_id').val(id_almacen);
$('#deleteAlmacenModal').modal('show');
});
So, if you are using bootstrap you don't need to trigger the modal with jquery but let bootstrap do the magic.
Your code should be something like that:
html:
<table id="tablaAlmacenes" class="table table-bordered table-striped">
<thead>
<tr>
<th>Almacén</th>
<th>Detalles</th>
<th></th>
</tr>
</thead>
<tbody>
{% for almacen in object_list %}
<tr>
<td>{{ almacen.almacen }}</td>
<td>{{ almacen.descripcion }}</td>
<td>
<div>
Detalles
<a a href="" class="btn btn-link text-primary">Editar</a>
<a class="btn btn-link" data-toggle="modal" data-target="#deleteAlmacenModal{{almacen.id}}""><span class="fas fa-trash text-danger"></a> <!-- data-toggle and data-target work in bootstrap4, in 5 is data-bs-target and data-bs-toggle -->
{% include 'yourtemplatefolder/modals/delete_almacen_modal.html' %} <!-- as best practice create another folder called modals and put there you modal.html files, as in this case and include them in your code -->
</div>
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Almacén</th>
<th>Detalles</th>
<th></th>
</tr>
</tfoot>
</table>
Now, being the modal called inside the for loop, you can fix your modal like this:
delete_almacen_modal.html
<div class="modal fade" aria-modal="false" id="deleteAlmacenModal{{almacen.id}}">
<div class="modal-dialog modal-dialog-centered modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirmación</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>¿Desea eliminar el Almacen?</p>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<form action="{% url 'eliminar_almacen' pk=almacen.id %}" method="POST">
{% csrf_token %}
<input type="hidden" name="id" id="almacen_id"/>
<button type="submit" class="btn btn-danger">Eliminar</button>
</form>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
Now that should work.

NoReverseMatch Django Project

I want to create the products through the customer's profile, so that the customer's name is attached to the form when creating the product that is related to it. But when I try to enter the user profiles from the dashboard it throws this error
urls.py
urlpatterns = [
path('', views.home, name="home"),
path('products/', views.products, name="products"),
path('customer/<str:pk_test>/', views.customer, name="customer"),
path('create_order/<str:pk>', views.createOrder, name='create_order'),
path('update_order/<str:pk>', views.updateOrder, name='update_order'),
path('delete_order/<str:pk>', views.deleteOrder, name='delete_order'),
path('create_customer/', views.createCustomer, name='create_customer'),
]
views.py
Here I focus on the "create Order" function passing the customer's primary key and using "initial" to append the customer's name to the form
def home(request):
orders_value = Order.objects.all()
customer_value = Customer.objects.all()
total_orders_value = orders_value.count()
total_customers_value = customer_value.count()
pending_value = orders_value.filter(status='Pending').count()
delivered_value = orders_value.filter(status='Delivered').count()
context = {'orders_key': orders_value, 'customer_key': customer_value,
'total_orders_key':total_orders_value, 'pending_key': pending_value,
'delivered_key': delivered_value}
return render (request, 'accounts/dashboard.html', context)
def products(request):
products_value = Product.objects.all()
return render (request, 'accounts/products.html', {'products_key': products_value})
def customer(request, pk_test):
customer_value = Customer.objects.get(id=pk_test)
orders_value = customer_value.order_set.all()
orders_value_count = orders_value.count()
context = {'customer_key':customer_value, 'orders_key': orders_value, 'orders_key_count': orders_value_count}
return render (request, 'accounts/customer.html', context)
def createOrder(request, pk):
customer = Customer.objects.get(id=pk)
form_value = OrderForm(initial={'customer':customer})
if request.method == 'POST':
form_value = OrderForm(request.POST)
if form_value.is_valid:
form_value.save()
return redirect('/')
context = {'form_key':form_value}
return render(request, 'accounts/order_form.html', context)
def updateOrder(request, pk):
order = Order.objects.get(id=pk)
form_value = OrderForm(instance=order)
if request.method == 'POST':
form_value = OrderForm(request.POST, instance=order)
if form_value.is_valid:
form_value.save()
return redirect('/')
context = {'form_key':form_value}
return render(request, 'accounts/order_form.html', context)
def deleteOrder(request, pk):
order = Order.objects.get(id=pk)
if request.method == 'POST':
order.delete()
return redirect('/')
context={'item':order}
return render (request, 'accounts/delete.html', context)
customer.html
{% extends 'accounts/main.html' %}
{% block content %}
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<h5>Customer:</h5>
<hr>
<a class="btn btn-outline-info btn-sm btn-block" href="">Update Customer</a>
<a class="btn btn-outline-info btn-sm btn-block" href="{% url 'create_order' customer.id %}">Place Order</a>
</div>
</div>
<div class="col-md">
<div class="card card-body">
<h5>Contact Information</h5>
<hr>
<p>Email: {{customer_key.email}}</p>
<p>Phone: {{customer_key.phone}}</p>
</div>
</div>
<div class="col-md">
<div class="card card-body">
<h5>Total Orders</h5>
<hr>
<h1 style="text-align: center;padding: 10px">{{orders_key_count}}</h1>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<div class="card card-body">
<form method="get">
<button class="btn btn-primary" type="submit">Search</button>
</form>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<table class="table table-sm">
<tr>
<th>Product</th>
<th>Category</th>
<th>Date Orderd</th>
<th>Status</th>
<th>Update</th>
<th>Remove</th>
</tr>
{% for order in orders_key %}
<tr>
<td>{{order.product}}</td>
<td>{{order.product.category}}</td>
<td>{{order.data_created}}</td>
<td>{{order.status}}</td>
<td>{{order.product}}</td>
<td><a class="btn btn-sm btn-info" href="{% url 'update_order' order.id %}">Update</a></td>
<td><a class="btn btn-sm btn-danger" href="{% url 'delete_order' order.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
dashboard.html
{% extends 'accounts/main.html' %}
{% block content %}
{% include 'accounts/status.html' %}
<br>
<div class="row">
<div class="col-md-5">
<h5>CUSTOMERS:</h5>
<hr>
<div class="card card-body">
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_customer' %}">Create Customer</a>
<table class="table table-sm">
<tr>
<th></th>
<th>Customer</th>
<th>Phone</th>
</tr>
{% for customer in customer_key %}
<tr>
<th><a class="btn btn-sm btn-info" href="{% url 'customer' customer.id %}">View</a></th>
<td>{{customer.name}}</td>
<td>{{customer.phone}}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
<div class="col-md-7">
<h5>LAST 5 ORDERS</h5>
<hr>
<div class="card card-body">
<table class="table table-sm">
<tr>
<th>Product</th>
<th>Date Orderd</th>
<th>Status</th>
<th>Update</th>
<th>Remove</th>
</tr>
{% for orders in orders_key %}
<tr>
<td>{{orders.product}}</td>
<td>{{orders.data_created}}</td>
<td>{{orders.status}}</td>
<td><a class="btn btn-sm btn-info" href="{% url 'update_order' orders.id %}">Update</a></td>
<td><a class="btn btn-sm btn-danger" href="{% url 'delete_order' orders.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
This is the error that throws me
NoReverseMatch at /customer/1/
Error during template rendering
Reverse for 'create_order' with arguments '('',)' not found. 1 pattern(s) tried: ['create_order/(?P<pk>[^/]+)$']
Maybe i wrote some wrong in "customer.html" but i dont know where and i cant find the error... I need help, please
inside your template customer.html
change this(why ? because inside your context = {'customer_key':customer_value, 'orders_key': orders_value, 'orders_key_count': orders_value_count} that refers to this template there is no key called 'customer' and you tried to access again his id that is not correct)
<a class="btn btn-outline-info btn-sm btn-block" href="{% url 'create_order' customer.id %}">Place Order</a>
to (if you look your context you have a customer_key that is from your Customer model to get his id you can just use customer_key.pk)
<a class="btn btn-outline-info btn-sm btn-block" href="{% url 'create_order' customer_key.pk %}">Place Order</a>
there is some mistake inside your urls.py(pk is an integer so instead of str(string) you should use int(integer))
urlpatterns = [
path('', views.home, name="home"),
path('products/', views.products, name="products"),
path('customer/<int:pk_test>/', views.customer, name="customer"),
path('create_order/<int:pk>', views.createOrder, name='create_order'),
path('update_order/<int:pk>', views.updateOrder, name='update_order'),
path('delete_order/<int:pk>', views.deleteOrder, name='delete_order'),
path('create_customer/', views.createCustomer, name='create_customer'),
]

The delete view doesn't erase the correspondent object

I'm developing the backend of my personal blog and I've create a view that delete a single tag of the post.
views.py
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.text import slugify
from .forms import BlogTagForm
from .models import BlogTag
def deleteBlogTag(request, slug_tag):
if request.method == 'POST':
tag = BlogTag.objects.get(slug_tag=slug_tag)
tag.delete()
return redirect('tag_list')
models.py
from django.db import models
from django.urls import reverse
class BlogTag(models.Model):
tag_name = models.CharField(
'Tag',
max_length=50,
help_text="Every key concept must be not longer then 50 characters",
unique=True,
)
slug_tag = models.SlugField(
'Slug',
unique=True,
help_text="Slug is a field in autocomplete mode, but if you want you can modify its contents",
)
def __str__(self):
return self.tag_name
def get_absolute_url(self):
return reverse("single_blogtag", kwargs={"slug_tag": self.slug_tag})
class Meta:
ordering = ['tag_name']
urls.py
path("tags/", views.listTagAdmin, name='tag_list_admin'),
path("create-tag/", views.createBlogTag, name='create_tag'),
path("update-tag/<str:slug_tag>/", views.updateBlogTag, name='update_tag'),
path("delete-tag/<str:slug_tag>/", views.deleteBlogTag, name='delete_tag'),
tag_list.html
<table class="table table-striped">
<thead class="bg-secondary text-white">
<tr>
<th colspan="3"><h1 class="text-center"><strong>Tag List</strong></h1></th>
</tr>
<tr>
<th colspan="1">Tag</th>
<th colspan="1">Related Posts</th>
<th class="text-center" colspan="1">Actions</th>
</tr>
</thead>
<tbody>
{% for tag in tag_list %}
<tr>
<td colspan="1">{{ tag.tag_name }}</td>
<td colspan="1">{{ tag.tag_blogpost.count }}</td>
<td colspan="1">
<div class="row justify-content-md-center">
<a class="btn btn-success btn-sm mx-1" href="{% url 'update_tag' slug_tag=tag.slug_tag %}">Update</a>
<button class="btn btn-danger btn-sm mx-1" type="button" data-toggle="modal" data-target="#deleteModal">Delete</button>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title text-center" id="deleteModalLabel">Delete Request</h2>
</div>
<div class="modal-body">
<h3>Are you sure to delete this tag?</h3>
<h1 class="py-4"><em><strong>{{ tag.tag_name }}</strong></em></h1>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">No, don't do this</button>
<form action="{% url 'delete_tag' slug_tag=tag.slug_tag %}" method="POST">
{% csrf_token %}
<button class="btn btn-danger btn-sm" type="submit" name="button">Yes, delete it</button>
</form>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
The problem is that it's not possible to delete every single objects of the list but only the first object. Even if I try to delete the last object I delete the first object instead of the last.
Where I've wrong?
All your modal forms are named the same, hence it will pick one. If it searches for a specific id, it will pick one. In order to solve this, you should give your modals different ids:
<tbody>
{% for tag in tag_list %}
<tr>
<td colspan="1">{{ tag.tag_name }}</td>
<td colspan="1">{{ tag.tag_blogpost.count }}</td>
<td colspan="1">
<div class="row justify-content-md-center">
<a class="btn btn-success btn-sm mx-1" href="{% url 'update_tag' slug_tag=tag.slug_tag %}">Update</a>
<button data-target="#deleteModal{{ tag.pk }}" class="btn btn-danger btn-sm mx-1" type="button" data-toggle="modal">Delete</button>
<div class="modal fade" id="deleteModal{{ tag.pk }}" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title text-center" id="deleteModalLabel">Delete Request</h2>
</div>
<div class="modal-body">
<h3>Are you sure to delete this tag?</h3>
<h1 class="py-4"><em><strong>{{ tag.tag_name }}</strong></em></h1>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">No, don't do this</button>
<form action="{% url 'delete_tag' slug_tag=tag.slug_tag %}" method="POST">
{% csrf_token %}
<button class="btn btn-danger btn-sm" type="submit" name="button">Yes, delete it</button>
</form>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
So here we added a suffix to the id of the <div class="modal fade" id="deleteModal{{ tag.pk }}" ...>, and used the same id in the <button target="#deleteModal{{ tag.pk }}" ...>.

How to create such a table with checkbox in django?

I want to have a table with a checkbox on each row with Django as shown in the image. My Django view.py, models.py and HTML file are mentioned below. How this can be done? Is there any built-in function in Django or what?
Table with check box
I have models file as:
class AppsDescription(db.Model):
aws_response = aws_list_conf_api_call()
CHOICES = [("yes", "YES"),
("no", "NO")]
OPTIONS = list()
for apps in aws_response:
OPTIONS.append(('{name1}'.format(name1=apps.lower()), '{name2}'.format(name2=apps)), )
name = db.CharField(max_length=256)
description = db.TextField()
plan_to_migrate = db.CharField(choices=CHOICES, max_length=256)
# app_names = MultiSelectField(choices=OPTIONS)
def __str__(self):
return self.name
My views.py as
def createapp(request):
# import ipdb; ipdb.set_trace()
form = DashboardForm()
if request.method == "POST":
form = DashboardForm(request.POST)
list_of_inputs = request.POST.getlist("inputs")
if form.is_valid:
form.save(commit=True)
return HttpResponseRedirect(reverse("aws:createapp"))
server = aws_server_list_conf()
return render(request, "createapp.html", {'server':server, 'form': form})
My html file as
<form method="POST">
{{form.as_p}}
<table>
<tr>
<th>Select</th>
<th>Agent ID</th>
<th>Configuration ID</th>
<th>Host Name</th>
<th>OS Name</th>
<th>OS Version</th>
<th>Source</th>
<th>Time of Creation</th>
<th>Type</th>
</tr>
{% for apps in server %}
<tr>
<td><input type="checkbox" name="" value=""></td>
{% for k,v in apps.items %}
<td>{{ v }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% csrf_token %}
<input type="submit" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" name="" value="submit">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="alert alert-success alert-dismissible">
<a class="close" data-dismiss="modal" aria-label="close">×</a>
<strong>Success!</strong> App information stored Successfully.
</div>
</div>
</div>
</form>
I want to have a table with checkbox on each row with django as shown in the image.
Your HTML file needs to look like this:
<form method="POST">
{{form.as_p}}
<table>
<tr>
<th>Select</th>
<th>Agent ID</th>
<th>Configuration ID</th>
<th>Host Name</th>
<th>OS Name</th>
<th>OS Version</th>
<th>Source</th>
<th>Time of Creation</th>
<th>Type</th>
</tr>
{% for apps in server %}
<tr>
{% for k,v in apps.items %}
<td><input type="checkbox" name="selected_options" value="v.id"></td>
<td>{{ v }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% csrf_token %}
<input type="submit" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" name="" value="submit">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="alert alert-success alert-dismissible">
<a class="close" data-dismiss="modal" aria-label="close">×</a>
<strong>Success!</strong> App information stored Successfully.
</div>
</div>
</div>
</form>

How to open a template as modal (detail user data) in user_list page (Django 1.11)

I have a user list page which works fine, and a user detail page which works fine too that I call from urls.py in seperate window. I want to open user detail in user list page in a modal window.
user_list.html
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr userid="{{user.id}}" class="edit_user">
<td>{{user.first_name}}</td>
<td>{{user.last_name }}</td>
<td>{{user.username }}</td>
<td>
<form class="right user_delete" method="POST" userid="{{user.id}}"
action="{% url 'user_delete' user.id%}">
{% csrf_token %}
<input class="btn btn-danger btn-sm" type="submit" value="DELETE">
</form>
</td>
<td><a type="button" class="btn btn-primary edit_user" href="{% url 'user_details' user.id %}" target="#edit_user"> UPDATE </a></td>
</tr>
{% empty %}
<tr>
<td>No Projects.</td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#registerformmodal"> New user </button>
user_detail.html
<h1>User Details</h1>
<p>{{ user_details.username }}</p>
<p>{{ user_details.first_name }}</p>
views.py
def user_details(request, userid):
user = User.objects.get(id=userid)
template = loader.get_template('vts/user_detail.html')
context = {
'user_details': user,
}
return HttpResponse (template.render(context, request))
The button data-target here,
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#registerformmodal"> New user </button>
looks for #registerformmodal which is neither associated with <form> nor <div>
You can add the id to your form as this
<form id="#registerformmodal" class="right user_delete" method="POST" userid="{{user.id}}">
...
</form>