class Profile没有属性'_meta'

时间:2014-11-17 06:10:27

标签: django django-models django-forms django-views

虽然this suggests使用model.Models模型具有Meta属性,但我得到上面提到的错误 没有属性错误&#39; _meta&#39; < / strong>尽管如此。

在models.py

class Profile(models.Model):
    username = models.CharField(max_length=LENGTH)
    password = models.CharField(max_length=LENGTH)

    def __str__(self):
        print self.username

在forms.py

class LoginForm(forms.ModelForm):
    class Meta:
        model = Profile
        fields = ['username', 'password']
        widgets = {
            'password': forms.PasswordInput,
        }

在views.py 中:

class LoginFormView(FormView):
    form_class = LoginForm
    template_name = 'pv_ui/login_form.html'

可以在下面查看追溯:

Traceback:
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  343.             for pattern in self.url_patterns:
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  372.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  366.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/tilaprimera/PycharmProjects/djwork/pv/pv/urls.py" in <module>
  19.                            r'^nano/', include('pv_ui.urls')
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
  28.         urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/tilaprimera/PycharmProjects/djwork/pv/pv_ui/urls.py" in <module>
  2. from views import LoginFormView, UploadServer #, UploadFormView,
File "/home/tilaprimera/PycharmProjects/djwork/pv/pv_ui/views.py" in <module>
  10. from .forms import LoginForm, UploadForm#, UploadFormSet
File "/home/tilaprimera/PycharmProjects/djwork/pv/pv_ui/forms.py" in <module>
  10. class LoginForm(forms.ModelForm):
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/forms/models.py" in __new__
  284.                                       opts.help_texts, opts.error_messages)
File "/home/tilaprimera/.virtualenvs/nano/lib/python2.7/site-packages/django/forms/models.py" in fields_for_model
  184.     opts = model._meta

Exception Type: AttributeError at /nano/login/
Exception Value: class Profile has no attribute '_meta''

0 个答案:

没有答案