H
H
Held69912021-10-05 02:58:17
Django
Held6991, 2021-10-05 02:58:17

How to fix request.META.HTTP_REFERER reading error?

Hello, I want to change the variable in views by the presence of a specific referrer with the following code:

def startpage(request):
    success = False
    if request.META.HTTP_REFERER == 'http://127.0.0.1:8000/success':
        success = True
    return render(request, './index.html', {'success': success})

I placed a button on the page http://127.0.0.1:8000/successthat redirects to http://127.0.0.1:8000, i.e. to the start page displayed by startpage() By clicking on the button, an error page is displayed with the following content:
<a href="./">To start page</a>
AttributeError at /
'dict' object has no attribute 'HTTP_REFERER'

But moving a little lower down the page with the Django error, I see this:
615b947bef05d924328307.png
Added print request.META to the beginning of the startpage method:
615b94db173d7794752491.png
Please tell me where the jamb is in my implementation, how to fix it, or maybe some other options for implementing this idea, thanks to everyone in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-10-05
@Held6991

request.META['HTTP_REFERER']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question