I have a problem in Django where my pages are redirecting to wrong pages. It just somehow happen to the new page I am coding which I have no idea why.
urls.py
path('job/', JobListView.as_view(), name = 'jobs'),
path('job/edit/<int:pk>/', views.job_edit, name='job-edit'),
path('device_add/', views.device_add, name='device-add'),
views.py
class JobListView(ListView):
model = Job
template_name = 'interface/job.html' #<app>/<model>_<viewtype>.html
context_object_name = 'jobs'
ordering = ['date_added']
def job_edit(request, pk):
job = Job.objects.get(pk=pk)
#if request.method =="POST":
return render(request, 'interface/job_edit.html',{'job': job})
My html for my job_edit has the following:
<div class="row">
<div class="col-md-12">
<div class="text-sm-right">
<button class="btn btn-outline-secondary" type="submit">Save</button>
<a href="{% url 'jobs' %}">
<button class="btn btn-outline-secondary"> Back</button>
</a>
</div>
</div>
</div>
As stated in my urls.py, the url is job/
and name = jobs
, which I want the back
button to redirect back to job/
. But whenever i pressed the back
button, it somehow redirect back to device_add/
. Same goes for my save
button. As in my views, I have not coded the if part for request.method=='POST'
. But when i attempt to press the save button, it redirect to device_add/
. Can anyone explain what I am doing wrong?