TypeError at /add_atr/
add_atr() takes 0 positional arguments but 1 was given
Request Method: GET
Request URL: http://127.0.0.1:8000/add_stu/
Django Version: 3.0.3
Exception Type: TypeError
Exception Value:
add_atr() takes 0 positional arguments but 1 was given
Exception Location: E:\env\django9\lib\site-packages\django\core\handlers\base.py in _get_response, line 113
Python Executable: E:\env\django9\Scripts\python.exe
Python Version: 3.6.5
Python Path:
['E:\\workspace\\9.django\\day01',
'E:\\workspace\\9.django\\day01',
'E:\\env\\django9\\Scripts\\python36.zip',
'E:\\env\\django9\\DLLs',
'E:\\env\\django9\\lib',
'E:\\env\\django9\\Scripts',
'c:\\users\\wyq\\appdata\\local\\programs\\python\\python36\\Lib',
'c:\\users\\wyq\\appdata\\local\\programs\\python\\python36\\DLLs',
'E:\\env\\django9',
'E:\\env\\django9\\lib\\site-packages']
解决方案:
在views.py视图中定义的方法中缺少request参数,它作用是用来获取请求的方式POST。
例如:
def add_atr(request):
if request.method == ‘POST’:
atr = Article()
atr.title = ‘学校公告’
atr.desc = ‘关于学校的一些公告’
atr.save()
return HttpResponse(‘创建成功’)