A
A
Anton Kuznetsov2019-03-27 00:19:17
Django
Anton Kuznetsov, 2019-03-27 00:19:17

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})

and template:
<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>

Clicking the save button opens the index (template) in a new browser tab, but I'm expecting it to open in the same tab. Please tell me what are the options to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anokhinem, 2019-03-28
@anokhinem

Remove target="_blank" from the template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question