我在Django中使用重定向from django.shortcuts import redirect
我想要的是,在重定向前向用户显示一个JavaScript警报消息。
这是我目前的代码:
response = redirect("someUrl")
response.write('<script>alert(\'You must remove an item before adding another\');</script>')
response['location'] += "?active=" + "all"
return response
重定向可以实现,但JavaScript无法运行。我还尝试了其他方法。
response = HttpResponse('<script>alert(\'You must remove an item before adding another\');</script>')
return response
这会触发警报窗口,但我不确定如何添加与上述方法相当的重定向。