Django注册或django auth?

时间:2022-06-02 00:24:50

I am new to Django and trying to build a social networking site that requires these steps for new users:

我是Django的新手,并试图建立一个社交网站,需要为新用户采取这些步骤:

Fill Registration forms -> Fill some profile forms -> Verify account from email -> Use

填写注册表格 - >填写一些个人资料表格 - >从电子邮件验证帐户 - >使用

pip has installed Django 1.5.4.

pip安装了Django 1.5.4。

My question is: For this Scenario, should I use Django-registraion or the native Django-auth or some other module? Which option would you recommend and why?

我的问题是:对于这个场景,我应该使用Django-registraion还是原生的Django-auth或其他模块?你会推荐哪种选择?为什么?

2 个解决方案

#1


1  

It really depends on the level of customization you want to have.

这实际上取决于您想要的定制级别。

A registration form could look a bit like repetitive task among different Django projects, and it is considering most of the registration processes require the same basic steps. However, for different projects you may need to extend or exclude certain steps.

注册表单看起来有点像不同Django项目中的重复任务,并且它正在考虑大多数注册过程需要相同的基本步骤。但是,对于不同的项目,您可能需要扩展或排除某些步骤。

This is an example of a view I use for registration:

这是我用于注册的视图的示例:

def register(request):
    if request.method == 'POST':
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            data = register_form.data

            # create user
            user = User.objects.create_user(
                username=data.get('username'),
                email=data.get('email'),
                password=data.get('password'),
            )

            if user is not None:
                auth = authenticate(username=data.get('username'), password=data.get('password'))
                login(request, auth)

                messages.success(request, _('Your new user has been created.'))
                return redirect(reverse('home'))
            else:
                messages.error(request, _('Oops! Error.'))
    else:
        register_form = RegisterForm()

    return render(request, 'accounts/register.html')

This works for almost all my projects. RegisterForm has all the magic.

这几乎适用于我的所有项目。 RegisterForm拥有所有的魔力。

#2


0  

django-allauth is a fairly complete solution. Even if you are not interested in the social login and integration features, it makes very easy for you to handle user registration, profile, email validation, etc.

django-allauth是一个相当完整的解决方案。即使您对社交登录和集成功能不感兴趣,也可以轻松处理用户注册,个人资料,电子邮件验证等。

#1


1  

It really depends on the level of customization you want to have.

这实际上取决于您想要的定制级别。

A registration form could look a bit like repetitive task among different Django projects, and it is considering most of the registration processes require the same basic steps. However, for different projects you may need to extend or exclude certain steps.

注册表单看起来有点像不同Django项目中的重复任务,并且它正在考虑大多数注册过程需要相同的基本步骤。但是,对于不同的项目,您可能需要扩展或排除某些步骤。

This is an example of a view I use for registration:

这是我用于注册的视图的示例:

def register(request):
    if request.method == 'POST':
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            data = register_form.data

            # create user
            user = User.objects.create_user(
                username=data.get('username'),
                email=data.get('email'),
                password=data.get('password'),
            )

            if user is not None:
                auth = authenticate(username=data.get('username'), password=data.get('password'))
                login(request, auth)

                messages.success(request, _('Your new user has been created.'))
                return redirect(reverse('home'))
            else:
                messages.error(request, _('Oops! Error.'))
    else:
        register_form = RegisterForm()

    return render(request, 'accounts/register.html')

This works for almost all my projects. RegisterForm has all the magic.

这几乎适用于我的所有项目。 RegisterForm拥有所有的魔力。

#2


0  

django-allauth is a fairly complete solution. Even if you are not interested in the social login and integration features, it makes very easy for you to handle user registration, profile, email validation, etc.

django-allauth是一个相当完整的解决方案。即使您对社交登录和集成功能不感兴趣,也可以轻松处理用户注册,个人资料,电子邮件验证等。