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

4đź‘Ť

âś…

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

👤patrys

2đź‘Ť

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.)

👤Karl Knechtel

Leave a comment