0

I am doing a web application using django framework. In a form in my app I need to go or redirect to a new page when the page is reloaded not when the form is posted. Really appreciate the community for your answers.

app.html

  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

  </head>
  <body>
  <form method="post">
    {% csrf_token %}
    #somecode
    <button type="submit" class="btn btn-primary">YES</button>
</form>
</body>
</html>

When this page is relaoded or refreshed I need to go to a new page(my home page in views.py)

2 Answers2

0

Use this in form tag to open in new tab : < form method="post" target="_blank">

0

Let's assume this is your form:

form.html(template name)

<form method="post">
    {% csrf_token %}
    #somecode
    <button type="submit" class="btn btn-primary">YES</button>
</form>

you have a view from where you are rendering this template.Write this view as:

def viewname(request):
    if request.method=='POST':
        form=formname(request.POST)
        if form.is_valid():
            do_your_work
            return redirect('you another view from where you will render another template/page')
    else:
        form = formname()
    return redirect(request, 'form.html', {'form':form})
hhhameem
  • 51
  • 6