开发者

Error: "can only concatenate tuple (not "list") to tuple" in urls, Django

I've got an error in my urls:

TypeError at / can only concatenate tuple (not "list") to tuple

Can't get what I did wrong. Where is the list in there?

from django.conf import settings

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = ('googleapi.apiapp.views',
    (r'^$', 'first_view'),
)

urlpatterns += patterns('',
    # Uncomment the admin/doc line below to enable admin documentation:
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),

    # Static files url.
    (r'^site_media/media/(?P<path>.*)$', 'django.views.static.serve',
                                   {'document_root': settings.MEDIA_ROOT}),
    (r'^site_media/static/(?P<path>.*)$', 'django.views.static.serve',
                                {'document_root': settings.STATIC_ROOT}),
)

Django Config

Traceback:

File "/home/i159/Env/googleapi/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/home/i159/Env/googleapi/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/home/i159/Env/googleapi/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/i159/Env/googleapi/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/home/i159/Env/googleapi/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/开发者_运维技巧home/i159/workspace/apiroot/googleapi/../googleapi/urls.py" in <module>
  24.                                     {'document_root': settings.STATIC_ROOT}),

Exception Type: TypeError at /
Exception Value: can only concatenate tuple (not "list") to tuple


The error pretty much describes your problem. You're missing a call to patterns() in your first definition of urlpatterns.


TypeError at / can only concatenate tuple (not "list") to tuple

It means exactly what it says. It is complaining about urlpatterns += patterns(...). The += attempts to concatenate (chain together) two things. urlpatterns is a tuple. The value returned by patterns(...) is a list. You can't mix these for concatenation.

To fix this, you must first decide whether you want a tuple or a list as the result (concatenating two tuples gives a tuple, and concatenating two lists gives a list), and then fix one side or the other accordingly.

In your case, you apparently want a list. The value you assign to urlpatterns first looks like a set of arguments for patterns(). The simple explanation, as @patrys points out, is that you meant (and forgot) to call the function here. That would give you a list, to which you could then append (concatenate) the list from the second call.

Note that you can also do it all in one go: urlpatterns = patterns(...) + patterns(...).

Where is the list in there?

The result of the patterns() calls, as explained above (and also by the documentation, presumably - I don't know anything about django, I'm just good at debugging.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜