Adding javascript to a Django redirect (HttpResponse)
<p>I am using a redirect in Django <code>from django.shortcuts import redirect</code></p>

<p>What I want, is for the user to be displayed a Javascript alert message before being redirected.</p>

<p>Here is what I've got so far:</p>

<pre><code>response = redirect("someUrl")
response.write('&lt;script&gt;alert(\'You must remove an item before adding another\');&lt;/script&gt;')
response['location'] += "?active=" + "all"
return response
</code></pre>

<p>The redirect works, but the Javascript does not. I also tried</p>

<pre><code>response = HttpResponse('&lt;script&gt;alert(\'You must remove an item before adding another\');&lt;/script&gt;')
return response
</code></pre>

<p>This triggers the alert window, but I'm not sure how to add an equivalent redirect as the method above.</p>

<p>You can use <code>js appproach</code> <code>window.location</code></p>

<pre><code>url = 'someUrl'
resp_body = '&lt;script&gt;alert("You must remove an item before adding another");\
             window.location="%s"&lt;/script&gt;' % url
return HttpResponse(resp_body)
</code></pre>

python django redirect httpresponse