I have confusion regarding what does request.user refers to in Django? Does it refer to username field in the auth_user table or does it refer to User model instance?
I had this doubt because I was not able to access email field in the template using {{request.user.username}}
or {{user.username}}
.
So instead I did following in views file:
userr = User.objects.get(username=request.user)
And passed userr
to the template and accessed email field as {{ userr.email }}
.
Although its working but I wanted to have some clarity about it.
In this Django tutorial, you will learn how to get data from get request in Django. When you send a request to the server, you can also send some parameters. Generally, we use a GET request to get some data from the server. We can send parameters with the request to get some specific data.
Whenever a request comes into Django, it is handled by middlewares. When the Django server starts, the first thing it loads after settings.py is middlewares. The Request is processed by various middlewares one at a time. So, from the above list, when the request comes it will be passed through the security middleware.
request. POST is an attribute of this request object, it's a QueryDict (much similar to a normal Python dict). It contains the HTTP POST parameters that are sent to your view.
What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.
request.user
is User model object.
You cannot access request object in template if you do not pass request
explicitly. If you want access user object from template, you should pass it to template or use RequestContext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With