我也提供一个用户注册的实现
```
class RegisterView(View):
template_name = 'accounts/simple_form.html'
def get(self, request, form=None):
if not form:
form = forms.RegisterForm()
data = {'title':'Register', 'form':form, 'btn_name':'Register'}
return render(request, self.template_name, data)
def post(self, request):
form = forms.RegisterForm(
request.POST)
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = User.objects.create_user(username, email, password)
user.save()
msg = 'Successfully Registered'
messages.add_message(request, messages.SUCCESS, msg)
url = reverse('accounts:login')
return redirect(url)
else:
return self.get(request, form)
```