You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

虚拟环境运行全新Django项目runserver时遇解包及include()参数错误

Fixing Django's "too many values to unpack" / "Passing a 3-tuple to include() is not supported" Error

Hey there, let’s sort out this Django runserver error you’re facing! The root cause here is pretty straightforward: you’re using an outdated syntax for the include() function in your project’s urls.py file—Django no longer supports passing a 3-element tuple to include(), which is why you’re seeing those two error messages.

What’s going wrong exactly?

In older Django versions, you might have written code like this in your root urls.py:

path('', include(('myapp.urls', 'myapp'), 'myapp'))

This passes a 3-tuple (the inner 2-element tuple plus the extra 'myapp' string) to include(), but modern Django expects either:

  • A single string pointing to your app’s URLconf, or
  • A 2-element tuple (URLconf path + app name) paired with an optional namespace keyword argument.

Step-by-Step Fix

  1. Open your project’s root urls.py file (usually mysite/urls.py in your case) and locate all instances of include().
  2. Adjust the syntax based on your needs:
    • No namespace needed? Simplify to just the string:
      path('', include('myapp.urls'))
      
    • Need a namespace? Use one of these supported approaches:
      • Option 1 (Recommended): First, add app_name = 'myapp' at the top of your app’s urls.py (e.g., myapp/urls.py). Then in the root urls.py:
        path('', include('myapp.urls', namespace='myapp'))
        
      • Option 2: Pass a 2-element tuple plus the namespace keyword argument:
        path('', include(('myapp.urls', 'myapp'), namespace='myapp'))
        
  3. Save your changes, then re-run python manage.py runserver—your server should start up without errors now!

Why this error happens

Django’s include() function was updated to stop supporting 3-tuple inputs. When you pass a 3-tuple, the underlying code tries to unpack only two values, leading to the "too many values to unpack" traceback, paired with the explicit "Passing a 3-tuple to include() is not supported" message.

内容的提问来源于stack exchange,提问作者gtx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:52:06