Hulk
Hulk

Reputation: 34190

How to know requested module name in Django

In Django if a request is made to another module. Can we know where the request has 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>

Upvotes: 1

Views: 129

Answers (1)

Dominic Rodger
Dominic Rodger

Reputation: 99811

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().

Upvotes: 1

Related Questions