0

I am using request.META.get('HTTP_REFERER') to get the referrer page from where current request is made. This function work fine when I am using HttpResponse to render UI. But, if there is an Ajax call which returns JsonResponse to the page, then request.META.get('HTTP_REFERER') return None.

Please guide me to solve this problem. Thanks

Fahad
  • 25
  • 5
  • 3
    What is the problem? It is definitely possible that not all requests will contain a `HTTP_REFERER` since that is something the browser injects. You can not be sure that it will contain that header (and definitely not that the value is *correct*). – Willem Van Onsem Dec 12 '19 at 16:38
  • Thanks Willem. If, it is not reliable, then how I can get the link of page from where request is made? Scenario is, users can upload there documents and can download these documents later. For downloading, I am using a view, which can be called by its url something like ```/download_docs/doc_name/```. User must be logged in but these documents should only be downloaded by hitting download button on page listing documents. Download must if user directly paste url in browser. – Fahad Dec 12 '19 at 16:48
  • This function is working correctly while the page loads for the first time but it stop working after getting some JsonResponse from Ajax call even if it is the same page. – Fahad Dec 12 '19 at 16:50

0 Answers0