简体   繁体   English

模型= Django Meta类中的用户

[英]model = User in Meta class of django

I am trying to read a code that concerns about user registration form. 我正在尝试阅读有关用户注册表单的代码。 The code has a Meta class which I know what it does, but assigning model to User doesn't give sense to me. 该代码具有一个Meta类,我知道它的作用,但是将模型分配给User对我没有意义。 Can you please explain it? 你能解释一下吗?

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    class Meta:
        model = User # explain?
        fields = ["username", "email", "password1", "password2"]

Django relies on Inner Classes to provide metadata, Your UserRegisterForm needs to know when you call UserRegisterForm.save() what database table to send this form data to. Django依靠内部类提供元数据,您的UserRegisterForm需要知道何时调用UserRegisterForm.save()将此表数据发送到哪个数据库表。

This is why you need model = User inside your Meta class, so the form knows where to go about storing. 这就是为什么在您的Meta类中需要model = User原因,因此表单知道在哪里存储。

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

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