我正在研究William S. Vincent编写的Django For Beginners。
当我尝试访问http://localhost:8000/accounts/signup/
时收到此错误:
Internal Server Error: /accounts/signup/
Traceback (most recent call last):
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/edit.py", line 168, in get
return super().get(request, *args, **kwargs)
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/edit.py", line 133, in get
return self.render_to_response(self.get_context_data())
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/edit.py", line 66, in get_context_data
kwargs['form'] = self.get_form()
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/edit.py", line 32, in get_form
form_class = self.get_form_class()
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/edit.py", line 93, in get_form_class
model = self.get_queryset().model
File "/Users/me/.local/share/virtualenvs/blog-dFYK_SP1/lib/python3.7/site-packages/django/views/generic/detail.py", line 73, in get_queryset
'cls': self.__class__.__name__
django.core.exceptions.ImproperlyConfigured: SignUpView is missing a QuerySet. Define SignUpView.model, SignUpView.queryset, or override SignUpView.get_queryset().
[19/Mar/2019 21:12:04] "GET /accounts/signup/ HTTP/1.1" 500 94136
This is the source code for the particular chapter I'm looking at。据我所知,我已经完全复制了它。我什至检查了缩进是否正确,看不到任何问题。
有什么要检查的吗?
答案 0 :(得分:0)
原来是一个错字。在我看来,我使用的是from_class
而不是 form_class
。
这应该是这样的:
class SignUpView(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'