开发者

How to know requested module name in Django

开发者 https://www.devze.com 2022-12-16 17:23 出处:网络
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 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().

0

精彩评论

暂无评论...
验证码 换一张
取 消