如何自定义django密码形式,不要使用默认密码形式

时间:2019-08-20 07:21:55

标签: django django-forms

我正在为我的django项目自定义重设密码表单,但是,它始终直接指向默认密码表单? 我可以自定义登录和注册表单,没问题,但是密码重置只是直接转到默认的密码表单。 我不知道会发生什么?

我使用django 2.2

project / urls.py

from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include('users.urls')),
    path('users/', include('django.contrib.auth.urls')),       
]

项目/用户/urls.py

from django.urls import path
from .views import SignUpView


urlpatterns = [
    path('signup/', SignUpView.as_view(), name='signup'),
]

项目/用户/views.py

f

rom django.urls import reverse_lazy
from django.views.generic import CreateView
from .forms import CustomUserCreationForm


class SignUpView(CreateView):
    form_class = CustomUserCreationForm
    success_url = reverse_lazy('login')
    password_reset_url = reverse_lazy('password_reset')
    template_name = 'signup.html'

项目/用户/forms.py

from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser


class CustomUserCreationForm(UserCreationForm):

    class Meta(UserCreationForm):
        model = CustomUser
        fields = ('username', 'email', 'age',)



class CustomUserChangeForm(UserChangeForm):

    class Meta:
        model = CustomUser
        fields = ('username', 'email', 'age',)

我的目录

enter image description here

0 个答案:

没有答案