3👍
You can use js appproach
window.location
url = 'someUrl'
resp_body = '<script>alert("You must remove an item before adding another");\
window.location="%s"</script>' % url
return HttpResponse(resp_body)
2👍
You are getting confused between frontend and backend. When this view is requested by the user, the server (via Django’s HTTPResponseRedirect
) is sending a 302
redirect HTTP response that tells the browser to redirect to a different page. This is different to a normal 200
response (i.e. a normal Django response object, not a redirect) within which you could include a javascript alert.
You need to show that javascript on the view you are initially loading before the user is returned the redirect response.
- [Django]-Customize queryset in django-filter ModelChoiceFilter (select) and ModelMultipleChoiceFilter (multi-select) menus based on request
- [Django]-Pandas- grouping and aggregating consecutive rows with same value in column
- [Django]-Problem rendering a Django form field with different representation
- [Django]-How to pass args to a signal
- [Django]-Is there a way to restrict apps based on IP?
Source:stackexchange.com