H
H
hexdim2019-12-21 18:22:34
Django
hexdim, 2019-12-21 18:22:34

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

2 answer(s)
H
hexdim, 2019-12-21
@hexdim

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'),

A
antonksa, 2019-12-22
@antonksa

There is a button in the editor to insert the code. The fact that you posted to read without syntax highlighting is just too lazy. But all depending on this, your solution will not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question