Answer the question
In order to leave comments, you need to log in
Django. Passing new post id to urls?
Tell me if we know the record id
def detail(request, employee_id):
a = Employee.objects.get( id = employee_id)
return render(request, 'employees/detail.html', {'employee' : a\
path(' /
'
, views.detail, name = 'detail'),
but
if
we let's create a post, how do we pass the created id? request.POST['surname'], empl_initials = request.POST['initials'], empl_position = request.POST['position'], empl_hired = request.POST['hired'])
a.save()
Got a new a .id, how to pass it to path('/', views.detail, name = ' detail')?
Answer the question
In order to leave comments, you need to log in
I figured it out, maybe it will be useful for someone else
return HttpResponseRedirect(reverse('employees:detail', args = (a.id,)))
path('save_empl/', views.save_empl, name = 'save_empl'),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question