Python 自定义django用户注册表

Python 自定义django用户注册表,python,django,Python,Django,我正在学习Django,我正在尝试制作自己的定制登记表。我当前遇到以下错误: Unknown field(s) (user) specified for User 以下是回溯: Traceback: File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/handlers/base.py" in get_response

我正在学习Django,我正在尝试制作自己的定制登记表。我当前遇到以下错误:

Unknown field(s) (user) specified for User
以下是回溯:

Traceback:
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/handlers/base.py" in get_response
  101.                 resolver_match = resolver.resolve(request.path_info)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in resolve
  320.                     sub_match = pattern.resolve(new_path)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in resolve
  222.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in callback
  229.         self._callback = get_callable(self._callback_str)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/utils/functional.py" in wrapper
  32.         result = func(*args)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in get_callable
  96.             mod = import_module(mod_name)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/utils/importlib.py" in import_module
  40.         __import__(name)
File "/Users/username/Development/django_tutorial/bin/django_test/django_test/views.py" in <module>
  10. from forms import MyRegistrationForm
File "/Users/username/Development/django_tutorial/bin/django_test/django_test/forms.py" in <module>
  7. class MyRegistrationForm(UserCreationForm):
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/forms/models.py" in __new__
  292.                 raise FieldError(message)

Exception Type: FieldError at /accounts/register/
Exception Value: Unknown field(s) (user) specified for User
我想你指的是“用户名”字段。模型用户没有“用户”字段。 对:

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

class MyRegistrationForm(UserCreationForm):
    email = forms.EmailField(required = True)

    # hold anything that isnt a form field (meta data)
    class Meta:
        model = User
        fields = ('user', 'email', 'password1', 'password2')    

    def save(self, commit = True):
        # save(commit = T/F) means save or dont save yet
        # calls the super method of this class (UserCreationForm) and calling it's save method with input as false
        user = super(MyRegistrationForm, self).save(commit = False)
        # cleaned_data makes things save to put in data base
        user.email = self.cleaned_data['email']

        if commit:
            user.save()

        return user
class Meta:
    model = User
    fields = ('username', 'email', 'password1', 'password2')