国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

python - [Django] How to get user information for each template
漂亮男人
漂亮男人 2017-07-05 10:34:29
0
5
1120

For example, if you use Django to build a website, most pages will contain user information, such as username, avatar, etc.

But it’s impossible for me to pass a user variable into the context for each view, right?

How do I usually achieve this requirement?

漂亮男人
漂亮男人

reply all(5)
typecho

You need to worry too much, you don’t need to write them one by one manually, it is already there by default, just use it, for example: {{user.username}}
But there is no custom field information such as avatar.
Or you can customize a context_processors.py to return the information you want, and then import it in settings.py. There is no need to return in every function

洪濤
如果你是使用的auth.login()登錄的話,你可以在任何一個(gè)模板里直接使用user對(duì)象
如{{user.username}}
Ty80

It should be {{request.user.username}}.
And django supports setting global variables

習(xí)慣沉默

After the user logs in, the user information will generally be stored in request.user. There is no need to pass the user variable into the context. The premise is that django.template.context_processors.request is referenced in settings

我想大聲告訴你

Additional point: If a fixed part of content appears on many pages, you can use template inheritance to extract the same parts, and modify the content of the template through extends and include.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template