使用Django中的Contrib.Auth生成登录和注册表单

时间:2022-11-17 19:19:00

I'm new to Django and in bouncing around the framework over the past few days I haven't been able to figure out how to properly install the django.contrib.auth app in my project. Well, installing is probably not the right word, but configuring it for my purposes.

我是Django的新手,并且在过去的几天里围绕框架反弹,我无法弄清楚如何在我的项目中正确安装django.contrib.auth应用程序。好吧,安装可能不是正确的词,但为我的目的配置它。

What I'm truly hoping to do is extend the built-in classes to simply create registration and login forms, since my User class is working just fine from terminal.

我真正希望做的是将内置类扩展为简单地创建注册和登录表单,因为我的User类在终端上运行得很好。

In settings.py I have django.contrib.auth in my INSTALLED_APPS. I also have installed the Authentication Middleware and Sessions Middleware.

在settings.py中,我的INSTALLED_APPS中有django.contrib.auth。我还安装了身份验证中间件和会话中间件。

I can also clearly see in Django.contrib.auth.views and Django.contrib.auth.forms where the registration and authentication handlers are.

我还可以在Django.contrib.auth.views和Django.contrib.auth.forms中清楚地看到注册和身份验证处理程序所在的位置。

My problem, it seems, since I'm new to the framework, is properly including these files in my project and generating the HTML forms for registration and login.

我的问题似乎是,因为我是框架的新手,正确地将这些文件包含在我的项目中并生成用于注册和登录的HTML表单。

(As in, do I need to include these Auth files in my app's forms.py? What do I need to model that hasn't already been modeled for me? And finally, since I can see in Django.contrib.auth.views a need for a registration directory with HTML templates, how can I get these all communicating with each other properly?)

(因为,我是否需要在我的应用程序的forms.py中包含这些Auth文件?我还需要建模哪些尚未为我建模?最后,因为我可以在Django.contrib.auth.views中看到需要一个带有HTML模板的注册目录,我如何能够正确地相互通信?)

Figured out the problem. Just needed to follow Django's URL Conf conventions. Example: (r'^accounts/login/$', 'django.contrib.auth.views.login'),

找出问题所在。只需要遵循Django的URL Conf约定。示例:(r'^ accounts / login / $','django.contrib.auth.views.login'),

1 个解决方案

#1


4  

James Bennet's django-registration is an excellent helper application used for a common registration / login pattern.

James Bennet的django-registration是一个很好的帮助应用程序,用于常见的注册/登录模式。

#1


4  

James Bennet's django-registration is an excellent helper application used for a common registration / login pattern.

James Bennet的django-registration是一个很好的帮助应用程序,用于常见的注册/登录模式。