HI all,
I am facing a issue in my django website. the issue is that after i submit the form the original URL(the URL which will lead to form and also which handles the form in the action tag) wil get loaded again although i have used redirect which should redirect to another page
views.py
def attendance(request):
a=Engineer.objects.filter().values("EnggName")
today= datetime.now()
context={"form":AttendanceModelForm(),"a":a,"today":today}
m=[]
if request.method=="POST":
form=AttendanceModelForm(request.POST or None)
for course in a:
m.append(course['EnggName'])
if form.is_valid():
Status_Loc_pairs = zip(m,request.POST.getlist('Status'), request.POST.getlist('Loc'))
data_dicts = [{'Engg': Engg,'Status': Status, 'Loc': Loc} for Engg,Status, Loc in Status_Loc_pairs]
a7=Attendance.objects.filter(currentdate=today).values("Status","Loc")
if a7.exists():
messages.info(request,f"There seems to be some data entered on {today} Please double check as it may lead to confusions")
return redirect("check")
else:
for data in data_dicts:
form=AttendanceModelForm(data)
#form.save()
return HttpResponseRedirect("http://127.0.0.1:8000/attendance/completed/")
else:
return render(request,"attendance/attendance.html",context)
urls
from django.urls import path
from . import views
urlpatterns=[path('main/', views.attendance, name='attendance'),
path('main_reuser/', views.test, name='test'),
path('checkagain/', views.check, name='check'),
path("completed/",views.completed, name="complete")]
html
{% load static %}
<html>
<head>
<title>hellaaa</title>
<title>AttendanceSheet</title>
<link rel="stylesheet" href="{% static 'dataview/bootstrap.min.css' %}">
<script src="{% static 'dataview/jquery.min.js' %}"></script>
<script src="{% static 'dataview/popper.min.js' %}"></script>
<script src="{% static 'dataview/bootstrap.min.js' %}"></script>
<script src="{% static 'newdata/htmx.min_1.9.5.js' %}"></script>
</head>
<body>
<form hx-post="{% url 'attendance' %}" id="test11" hx-trigger="click from:#submitall">
{% csrf_token %}
<table class="table table-bordered" id="attender">
<thead>
<th>Engineer</th>
<th>Status</th>
<th>Location</th>
</thead>
<tbody>
{% for j in a %}
<td>{{ j.EnggName }}</td>
<td>{{ form.Status }}</td>
<td>{{ form.Loc }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</head>
INITIAL FORM
Form after submission
Although redirect was given in code it is staying in the same url but is printing contents of the form page and the redirect page("thanks for the data is part of the redirect page)