Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to open a new tab from django views

I have a submitting form, that on submit is doing some complex process and then in django views I have this:

return redirect('match:finding', ...)

Could I add something to views to make this redirection not on the page where submit form was completed, but in new tab? Like, leaving tab with form as it is, and then open a new window to continue the process.

In html template it looks like this:

<div class="form-input">
<input id="app-submit" type="submit" value="{% if credit_card %}Get Started{% else %}Loan{% endif %}"/>
</div>

I can't just add a/span tag with target="_blank" or window.open('url', 'new window') as the url will be generated after actually clicking submit button.

like image 519
Olya Bogdanova Avatar asked Dec 16 '16 18:12

Olya Bogdanova


1 Answers

Add a target="_blank" attribute in your form [1]. Since you're redirecting, it doesn't matter if url is generated after submit.

Example setup would be somewhat like this:

-- views.py

def ex_form_view(request):
    ...
    return redirect('...', ...)

-- urls.py

 url(r'^ex_form', views.ex_form_view, name='example')

-- template.html

 <form action="ex_form" target="_blank">
   <input id="app-submit" type="submit" value="{% if credit_card %}Get Started{% else %}Loan{% endif %}"/>
 </form>

[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#Attributes

like image 200
Prashant Sinha Avatar answered Oct 08 '22 19:10

Prashant Sinha