Answer the question
In order to leave comments, you need to log in
Django - create a form and go to its detail?
Hi everybody!
Why when creating a form:
def contact_add(request, template_name="contact_add.html"):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
# ...
return HttpResponseRedirect(revers('contact_details'))
else:
form = ContactForm()
return render(request, template_name, {'form': form, })
def contact_details(request, contact_id, template_name="contact_details.html"):
contact_details = get_object_or_404(Contact, id=contact_id)
ctx = {'contact_details': contact_details}
return render(request, template_name, ctx)
urls.py
url(r'^add/$', views.contact_add, name='accessories_add'),
url(r'^detail/(?P<contact_id>\d+)/$', views.contact_details, name='contact_details'),
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question