Error when using include('admin.site.urls'): Passing a 3-tuple to include() is not supported
Asked Answered
O

2

7

I'm fairly new to Python and I am using a video tutorial on Lynda to help me build the frameworks for a Social WebApp. I'm trying to run the server from the cmd using python manage.py runserver from the cmd, however, I keep running into this error message.

CMD PROMPT ERROR

Traceback (most recent call last):

File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\management\base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\management\base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\checks\registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\utils\functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\urls\resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\utils\functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\urls\resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\Kelechi\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "C:\Windows\SysWOW64\bookmarks\bookmarks\urls.py", line 20, in <module>
    url(r'^admin/', include(admin.site.urls)),
  File "C:\Users\Kelechi\AppData\Roaming\Python\Python35\site-packages\django\urls\conf.py", line 27, in include
    'provide the namespace argument to include() instead.' % len(arg)
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

My urls.py looks like this:

from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    ...
]
Overheat answered 11/1, 2018 at 9:10 Comment(2)
There's no point showing extracts from the Django code itself. You should show your code, in this case the URL configuration that is using include().Miaow
If you're following a tutorial, it's much easier to use the same version of Django that the tutorial was written for, otherwise you'll hit confusing errors like this. If it was written for Django 1.9/1.10 (which are no longer supported) then it would be better to use Django 1.11 instead of Django 2.0.Stamps
S
12

In Django 2.0 you can no longer use include(admin.site.urls) (release notes). Just use admin.site.urls instead.

from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    ...
]
Stamps answered 11/1, 2018 at 9:53 Comment(1)
Just to note that this is only for admin.site.urls. Everything else (such as wagtail and your own application urls) requires include(xxx) still.Jangro
E
-1

Including another URLconf :

  1. Import the include() function : from django.urls import include, path
  2. Add a URL to urlpatterns : path('blog/', include('blog.urls'))

I was having this trouble and it was a simple as of putting your url into single quotes.

Escallop answered 27/11, 2022 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.