我在Django视图上有此错误:
TypeError at /web/host/1/
decorator() got an unexpected keyword argument 'host_id'
Request Method: GET
Request URL: http://127.0.0.1:8000/web/host/1/edit
Django Version: 1.10.4
Exception Type: TypeError
Exception Value:
decorator() got an unexpected keyword argument 'host_id'
Run Code Online (Sandbox Code Playgroud)
urlpatterns是:
url(r'^host/(?P<host_id>[0-9]+)$', host, name='host'),
Run Code Online (Sandbox Code Playgroud)
视图功能是:
@check_login
def host(request, host_id, *args, **kwargs):
h = Host()
# resultHost = h.get_host(host_id)
return render(request, 'web/host.html')
Run Code Online (Sandbox Code Playgroud)
check_login如下:
def check_login(f):
"""verify if user login"""
def decorator(request):
if request.session.get('user', None):
return f(request)
else:
return HttpResponseRedirect(reverse("web:login"))
return decorator
Run Code Online (Sandbox Code Playgroud)
如果我使用不带参数“ host_id”的url和不带host_id的宿主函数,则该程序将运行完美。
所以有什么问题?谢谢。