Python的Django框架入门踩过的坑(十三)

重写View的as_view方法的时候,需要声明为@classmethod,否则会出现以下错误




TypeError at /user/address
as_view() missing 1 required positional argument: 'cls'
Request Method: GET
Request URL: http://127.0.0.1:8000/user/address
Django Version: 1.8.7
Exception Type: TypeError
Exception Value:
as_view() missing 1 required positional argument: 'cls'
Exception Location: /home/python/Desktop/django/dailyfresh/apps/users/urls.py in <module>, line 18
Python Executable: /home/python/.virtualenvs/django_py3/bin/python
Python Version: 3.5.2
Python Path:
['/home/python/Desktop/django/dailyfresh',
 '/home/python/Desktop/django/dailyfresh',
 '/home/python/.virtualenvs/django_py3/lib/python35.zip',
 '/home/python/.virtualenvs/django_py3/lib/python3.5',
 '/home/python/.virtualenvs/django_py3/lib/python3.5/plat-x86_64-linux-gnu',
 '/home/python/.virtualenvs/django_py3/lib/python3.5/lib-dynload',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',

猜你喜欢

转载自blog.csdn.net/chenhua1125/article/details/80077838