简体   繁体   English

自定义Django登录页面

[英]Customize Django login page

i'm using django.contrib.auth to auth. 我正在使用django.contrib.auth进行身份验证。 user. 用户。 I'm using default login view, but i would like to add some more things (for example displaying number of already loge users). 我使用的是默认登录视图,但我想添加一些其他内容(例如,显示已登录用户的数量)。 Is there any way to customize that view or i have to copy-paste it to my project and chage some things inside that? 有什么方法可以自定义该视图,或者我必须将其复制粘贴到我的项目中并修改其中的某些内容? Is there are any way to call two views on one url? 有没有办法在一个网址上调用两个视图?

Remember, views are functions. 记住,视图是函数。 You can write your own view that calls Django's login view at the end: 您可以编写自己的视图,最后调用Django的登录视图

def mylogin(request):
    ...
    return login(request, 'my-login-template.html')

The kind of customization you want can happen in the template. 您想要的自定义类型可以在模板中进行。

The default login view doesn't provide a way to extend the template's context, you'll have to use a context processor for that, or write your own view and calling the login function instead, but that would mean writing more code which can introduce bugs. 默认的登录视图没有提供扩展模板上下文的方法,您必须为此使用上下文处理器,或者编写自己的视图并调用login函数 ,但这意味着编写更多可以引入代码的代码错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM