Django - 字典更新序列元素#0的长度为1;需要2个[重复]

时间:2022-10-10 02:27:49

This question already has an answer here:

这个问题在这里已有答案:

After i created new URLs, i got this error

在我创建新的URL后,我收到了这个错误

ValueError at /blog/ dictionary update sequence element #0 has length 1; 2 is required

/ blog / dictionary更新序列元素#0的ValueError长度为1; 2是必需的

Traceback

追溯

Request Method: GET
Request URL: http://127.0.0.1:8000/blog/

Django Version: 1.7.2
Python Version: 3.4.1
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'modeltranslation',
 'blog')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
  345.                     sub_match = pattern.resolve(new_path)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
  345.                     sub_match = pattern.resolve(new_path)
File "C:\Python34\lib\site-packages\django\core\urlresolvers.py" in resolve
  222.             kwargs.update(self.default_args)

Exception Type: ValueError at /blog/
Exception Value: dictionary update sequence element #0 has length 1; 2 is required

I use this urls

我用这个网址

# /project/urls.py
from blog.urls import urlpatterns as blog_urls

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^blog/', include(blog_urls, 'blog')),
)

# /blog/urls.py
urlpatterns = patterns('blog.views',
    url(r'^$', 'index', 'index'),
    url(r'^category/(?P<category_id>\d+)/$', 'category', 'category'),
)

# /blog/views.py
def index(request):
    render(request, 'blog/index.html')

def category(request, category_id):
    render(request, 'blog/index.html')

Why i got this error? Never saw it before and i don't know why i getting this error...

为什么我收到此错误?从来没有见过它,我不知道为什么我得到这个错误...

1 个解决方案

#1


20  

The problem is this line:

问题是这一行:

url(r'^category/(?P<category_id>\d+)/$', 'category', 'category')

The third positional parameter is the extra context dict. If you want to pass the name instead, you need to use a keyword arg:

第三个位置参数是额外的上下文字典。如果您想要传递名称,则需要使用关键字arg:

url(r'^category/(?P<category_id>\d+)/$', 'category', name='category')

#1


20  

The problem is this line:

问题是这一行:

url(r'^category/(?P<category_id>\d+)/$', 'category', 'category')

The third positional parameter is the extra context dict. If you want to pass the name instead, you need to use a keyword arg:

第三个位置参数是额外的上下文字典。如果您想要传递名称,则需要使用关键字arg:

url(r'^category/(?P<category_id>\d+)/$', 'category', name='category')