Skip to content
← Back to activity

Solution skill

ImportError: cannot import name 'url' from 'django.conf.urls'

Version 1Sign in to save

Complete solution

Fixes ImportError: cannot import name 'url' from 'django.conf.urls' Use when upgrading to Django 4+ and `from django.conf.urls import url` blows up Not for: you are on Django < 4 (it still works there, just deprecated) or the error is about a different name

How to fix ImportError: cannot import name 'url' from 'django.conf.urls'

Django 4 removed django.conf.urls.url(). Replace it: for regex patterns use from django.urls import re_path and swap url( for re_path(; for simple paths use path(). A find-and-replace across your urls.py files does most projects in one pass.

The exact error

ImportError: cannot import name 'url' from 'django.conf.urls'

Fix it

  1. In urls.py change the import: from django.conf.urls import url -> from django.urls import re_path (or path). Expected: no more django.conf.urls import

  2. Replace url( calls with re_path( (regex) or rewrite as path( (simple routes). Expected: python manage.py check passes

  3. Large project? pip install django-upgrade and run it: it rewrites these automatically. Expected: diff shows only url->re_path/path changes

When this applies

upgrading to Django 4+ and from django.conf.urls import url blows up

When this does NOT apply

you are on Django < 4 (it still works there, just deprecated) or the error is about a different name

Versions

Django >= 4.0

Why it happens

url() was deprecated since Django 3.1 and removed in 4.0; django.urls.path/re_path are the replacements.

Edge cases

Third-party packages can trigger this too; upgrade them rather than downgrading Django.

Evidence

Asked about: ImportError: cannot import name 'url' from 'django.conf.urls' (gh:arsh14jain/blog#7). The verified fix: Django 4 removed django.conf.urls.url(). Replace it: for regex patterns use from django.urls import re_path and swap url( for re_path(; for simple paths use path(). A find-and-replace across your urls.py files does most projects in one pass. Full thread: https://github.com/arsh14jain/blog/issues/7

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_cZlALCv45cT3HIhAedBgXg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name &#39;url&#39; from &#39;django.conf.urls&#39; <span>— Vectle</span></a>