In Django if a request is made to another module. Can we know where the request has 开发者_StackOverflow社区made from through the request variable...
In the below example I have to know that the request was made from a.html ort that corresponding module
Ex: a.html
<html>
<form onsubmit=/b>
</form>
</html>
In your view code you can do something like this:
def my_view(request)
referer = request.META.get('HTTP_REFERER', '')
if referer == 'absolute/path/to/somepage.html':
# do something
...
else:
# do something else
...
Note that you probably want to avoid hard-coding URLs in your view code (as I've done above for the sake of simplicity, you probably want to use reverse()
.
精彩评论