# Django 4.0 url import error

**URL:** <https://forum.djangoproject.com/t/django-4-0-url-import-error/11065>\
**Category:** Forms & APIs\
**Created:** [December 16, 2021, 1:43pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065 "2021-12-16T13:43:12Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [December 16, 2021, 1:43pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/1 "2021-12-16T13:43:12Z")

</div>

Hello i just installed the new version of Django

and I have this problem with importing the url in urls.py file

```auto
from django.contrib import admin
from django.urls import path 
from django.conf.urls import url
from ParamsMoni.views import index , get_data

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^api/data/$', get_data , name='api-data'),
    path('', index, name='index'),
]

```

I can’t import `from django.conf.urls import url` don’t now why and it gives me this error!

```auto
File "C:\XPTANK\Tankparms\urls.py", line 18, in <module>
    from django.conf.urls import url
ImportError: cannot import name 'url' from 'django.conf.urls' (C:\XPTANK\venv\lib\site-packages\django\conf\urls\ __init__.py)

```

I am using Django==4.0

my best

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 16, 2021, 1:49pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/2 "2021-12-16T13:49:15Z")

</div>

The [`url`](https://docs.djangoproject.com/en/3.2/ref/urls/#url) function was deprecated in 3.1 and [removed in 4.0](https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0).

---

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [December 16, 2021, 2:00pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/3 "2021-12-16T14:00:41Z")

</div>

So think the `path` do the same function but when I try

```
`path(r'^api/data/$', get_data , name='api-data'),`

```

and in the views.py

```auto
def get_data(request , *args, **kwargs):
    data= {
        "sales": 100,
        "customerts": 10,
    }
    return JsonResponse(data)

```

and from the browser `http://127.0.0.1:8000/api/data/`

it gives me error `Page not found (404)`

it there any way to solve this?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 16, 2021, 2:01pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/4 "2021-12-16T14:01:17Z")

</div>

Yes, did you read the documentation I linked to in my response?

---

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [December 16, 2021, 2:09pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/5 "2021-12-16T14:09:59Z")

</div>

nope, now I did 🙂

so the solution is to replace the `from django.conf.urls import url` by

`from django.urls import re_path`

and

```auto
urlpatterns = [
    path('admin/', admin.site.urls),
    re_path(r'^api/data/$', get_data , name='api-data'),
    path('', index, name='index'),
]

```

it works perfectly

Many thanks you are the best 🙂

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 16, 2021, 2:20pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/6 "2021-12-16T14:20:02Z")

</div>

Now that you’ve got it working, I’ll point out that using a regex in that situation doesn’t really provide any benefit. There are no variables in that path, nothing in the way of a “pattern” needing to be matched - just a straight string comparison.

You would be just as well served using `path('api/data/', get_data , name='api-data'),`

---

<div class="post-metadata">

**Author:** ![TaimoorDahar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/taimoordahar/32/7413_2.png) [@TaimoorDahar](https://forum.djangoproject.com/u/TaimoorDahar)\
**Post date:** [February 11, 2022, 4:00am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/7 "2022-02-11T04:00:24Z")

</div>

i’m also facing **ModuleNotFoundError: No module named 'pillow’**

Even i already installed pillow

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 11, 2022, 4:09am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/8 "2022-02-11T04:09:42Z")

</div>

This is a different problem. If you would like assistance with it, please open up a new topic in this category, thanks.

---

<div class="post-metadata">

**Author:** ![kola-Aderonmu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kola-aderonmu/32/8215_2.png) [@kola-Aderonmu](https://forum.djangoproject.com/u/kola-Aderonmu)\
**Post date:** [April 21, 2022, 10:28am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/9 "2022-04-21T10:28:15Z")

</div>

i have this issue too please; and my runserver shows errors:  
rom django.conf.urls import include, url  
from django.contrib import admin  
#from django.urls import path , re\_path

from clock import views  
from clock import views  
admin.autodiscover()

#from engrs.views import index , faq, forgot\_password, change\_password, profile, resume\_preview ,setting, updateView, deleteView, login\_view, logout\_view, wrong\_login, new\_personnel, saved, units, courses, education, separation, discipline, trade, posting

from django.conf import settings  
from django.conf.urls.static import static  
#from engrs import views  
#from django.urls import include, path

urlpatterns = [  
url(r’^$’, ‘clock.views.index’, name=‘index’),  
url( r’ admin/’, admin.site.urls), ]

===this is the error from the runserver terminal:  
Performing system checks…

Exception in thread django-main-thread:  
Traceback (most recent call last):  
File “/usr/lib/python3.8/threading.py”, line 932, in \_bootstrap\_inner  
self.run()  
File “/usr/lib/python3.8/threading.py”, line 870, in run  
self.\_target(\*self.\_args, \*\*self.\_kwargs)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/utils/autoreload.py”, line 64, in wrapper  
fn(\*args, \*\*kwargs)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/core/management/commands/runserver.py”, line 134, in inner\_run  
self.check(display\_num\_errors=True)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/core/management/base.py”, line 487, in check  
all\_issues = checks.run\_checks(  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/core/checks/registry.py”, line 88, in run\_checks  
new\_errors = check(app\_configs=app\_configs, databases=databases)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/core/checks/urls.py”, line 14, in check\_url\_config  
return check\_resolver(resolver)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/core/checks/urls.py”, line 24, in check\_resolver  
return check\_method()  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/urls/resolvers.py”, line 480, in check  
for pattern in self.url\_patterns:  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/utils/functional.py”, line 49, in **get**  
res = instance. **dict** [self.name] = self.func(instance)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/urls/resolvers.py”, line 696, in url\_patterns  
patterns = getattr(self.urlconf\_module, “urlpatterns”, self.urlconf\_module)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/utils/functional.py”, line 49, in **get**  
res = instance. **dict** [self.name] = self.func(instance)  
File “/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/urls/resolvers.py”, line 689, in urlconf\_module  
return import\_module(self.urlconf\_name)  
File “/usr/lib/python3.8/importlib/ **init**.py”, line 127, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
File “”, line 1014, in \_gcd\_import  
File “”, line 991, in \_find\_and\_load  
File “”, line 975, in \_find\_and\_load\_unlocked  
File “”, line 671, in \_load\_unlocked  
File “”, line 848, in exec\_module  
File “”, line 219, in \_call\_with\_frames\_removed  
File “/home/kola/Boom/GLUE/alarmclock/alarmclock/urls.py”, line 18, in   
from django.conf.urls import include, url  
ImportError: cannot import name ‘url’ from ‘django.conf.urls’ (/home/kola/Boom/GLUE/lib/python3.8/site-packages/django/conf/urls/ **init**.py)

please, need your help

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 21, 2022, 10:58am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/10 "2022-04-21T10:58:58Z")

</div>

This is a different problem. If you would like assistance with it, please open up a new topic in this category, thanks.

And when posting code here, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

---

<div class="post-metadata">

**Author:** ![kastalimohammed1965](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kastalimohammed1965/32/11027_2.png) [@kastalimohammed1965](https://forum.djangoproject.com/u/kastalimohammed1965)\
**Post date:** [November 24, 2022, 9:59am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/11 "2022-11-24T09:59:24Z")

</div>

worked for me too thnks a lot

---

<div class="post-metadata">

**Author:** ![NetherKing795](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/netherking795/32/12480_2.png) [@NetherKing795](https://forum.djangoproject.com/u/NetherKing795)\
**Post date:** [March 3, 2023, 1:53am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/12 "2023-03-03T01:53:22Z")

</div>

But re\_path doesnt work for me

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 3, 2023, 2:04am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/13 "2023-03-03T02:04:25Z")

</div>

If you’re having an issue that you would like assistance with, please open up a new topic and provide the relevant details. Include the source code causing the problem and any traceback you may be receiving.

And when posting code (or a traceback) here, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of `, then your code, then another line of `. This forces the forum software to keep your code properly formatted.  
Do not post images of code or error messages.

---

<div class="post-metadata">

**Author:** ![Dobbprince](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dobbprince/32/13358_2.png) [@Dobbprince](https://forum.djangoproject.com/u/Dobbprince)\
**Post date:** [April 21, 2023, 10:35am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/15 "2023-04-21T10:35:39Z")

</div>

from django.contrib import admin  
from django.urls import path  
import tgfmi

urlpatterns = [  
path(‘admin/’, admin.site.urls),  
path(‘api/data/’,get\_data , name=‘api-data’ (‘tgfmi.urls’))  
]

I tried running it on terminal and it’s telling me get data is not defined

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 21, 2023, 11:34am UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/16 "2023-04-21T11:34:36Z")

</div>

This issue is marked as solved, it’s not likely that new questions will be seen here.

If you’re having an issue that you would like assistance with, please open up a new topic and provide the relevant details. Include the source code causing the problem and any traceback you may be receiving.

And when posting code (or a traceback) here, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

---

<div class="post-metadata">

**Author:** ![Dobbprince](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dobbprince/32/13358_2.png) [@Dobbprince](https://forum.djangoproject.com/u/Dobbprince)\
**Post date:** [April 21, 2023, 12:01pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/17 "2023-04-21T12:01:55Z")

</div>

from django.urls import path  
from . import views

urlpatterns=[  
path(‘’,views.index,name=‘index’),

I ran it on terminal,

python manage.py runserver

It opens, going to  
127.0.0.1:8080/admin/

and it says

Page not found. Why, please help me!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 21, 2023, 12:48pm UTC](https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/18 "2023-04-21T12:48:13Z")

</div>

Again -

> [@KenWhitesell](#):
>
> This issue is marked as solved, it’s not likely that new questions will be seen here.
> 
> If you’re having an issue that you would like assistance with, please open up a new topic and provide the relevant details. Include the source code causing the problem and any traceback you may be receiving.
> 
> And when posting code (or a traceback) here, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

Please do not continue to add messages to this topic.
