Answer the question
In order to leave comments, you need to log in
How to open the page in the same browser tab after submitting the form?
There is a view:
def contacts_new(request):
if request.method == "POST":
form = ContactForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.published_date = timezone.now()
post.save()
return redirect('index')
else:
form = ContactForm()
return render(request, 'contacts/add_contact.html', {'form': form})
<form method="POST" accept-charset="UTF-8" class="post-form" autocomplete="off" target="_blank">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-success">Save</button>
</form>
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