dictionary update sequence element #0 has length 1; 2 is required解决方案

Traceback (most recent call last):
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ex
ception.py", line 41, in inner
    response = get_response(request)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ba
se.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ba
se.py", line 172, in _get_response
    resolver_match = resolver.resolve(request.path_info)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\urls\resolvers.p
y", line 364, in resolve
    sub_match = pattern.resolve(new_path)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\urls\resolvers.p
y", line 198, in resolve
    kwargs.update(self.default_args)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
[09/Dec/2018 01:51:09] "GET /infos/a/1482006/ HTTP/1.1" 500 68202
Internal Server Error: /infos/a/1482006/
Traceback (most recent call last):
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ex
ception.py", line 41, in inner
    response = get_response(request)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ba
se.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\handlers\ba
se.py", line 172, in _get_response
    resolver_match = resolver.resolve(request.path_info)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\urls\resolvers.p
y", line 364, in resolve
    sub_match = pattern.resolve(new_path)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\urls\resolvers.p
y", line 198, in resolve
    kwargs.update(self.default_args)

ValueError: dictionary update sequence element #0 has length 1; 2 is required

找了很久原因,发现是在urls.py urlpatterns配置里面

根本原因是因为我忘记了放置函数调用name=的最后一个参数url。
例如,下面的问题会抛出错误:

url(r'^index.html$', index.index,u"阿里云优惠券网"),

但实际上有效代码应该为:


url(r'^index.html$', index.index,name=u"阿里云优惠券网"),

回溯无效的原因是因为内部Django想要将给定的位置参数解析为关键字参数kwargs,并且由于字符串是可迭代的,所以非典型代码路径开始展开。始终在你的网址使用name=。



上一篇:阿里云ecs下一个django项目,同时搭建pc端和移动端教程
下一篇:利用阿里云函数计算做一些好玩的事情-案例实战