from django.conf.urls import url """ImportError

I have seen the similar error Django 4.0 url import error

My Django version is 4.2.7

I have change my urls.py following the instruction

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

 the solution is to replace the from django.conf.urls import url by
from django.urls import re_path
and
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^api/data/$', get_data , name='api-data'),
re_path('', index, name='index'),
]

I have followed the instruction
In my c:\learning_log\learning_log\urls.py

from django.conf.urls import include 
from django.contrib import admin
from django.urls import re_path      # add for the correction

urlpatterns = [
       re_path(r'^admin/', include(admin.site.urls)),                         # correct replace url by re_path
       re_path(r'', include('learning_logs.urls', namespace='learning_logs')), # correct replace url by re_path
]

this create a lot of error

(ll_env) C:\learning_log>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\EALALIN\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Users\EALALIN\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
   etc ....

What is strange is that the previous configuration was working very well before including "from django.conf.urls import url "

best regards
ealalin

I Have try this work around :

from django.urls import re_path as url

my urls.py

from django.conf.urls import include 
from django.contrib import admin
#from django.urls import re_path      # add for the correction
from django.urls import re_path as url

urlpatterns = [
       url(r'^admin/', include(admin.site.urls)),                         # correct replace url by re_path
       url(r'', include('learning_logs.urls', namespace='learning_logs')), # correct replace url by re_path
]

but I still have in the runserver

File "C:\learning_log\learning_log\urls.py", line 51, in <module>
    url(r'^admin/', include(admin.site.urls)),                         # correct replace url by re_path
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\learning_log\ll_env\Lib\site-packages\django\urls\conf.py", line 28, in include
    raise ImproperlyConfigured(
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.

Side note: When posting code or errors here, surround the code (or text) between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum software to keep your code properly formattted. (I’ve taken the liberty of editing your original posts, please remember to do this in the future.)

Review the docs at django.urls functions for use in URLconfs | Django documentation | Django to understand what the path and re_path functions do, and to understand how to update your url definitions.

Since you’re not using (or don’t need to use) regexes for your paths, you can use path instead of re_path.

Also read The Django admin site | Django documentation | Django

Note: If you get a new/different error, please post the complete traceback.

‘’’ The problem is resolved’‘’
‘’’ into c:\learning_log\learning_log\urls.py I have ‘’’

from django.urls import include, re_path
from django.contrib import admin

urlpatterns = [
re_path(r’^admin/‘, admin.site.urls),
re_path(r’', include((‘learning_logs.urls’, ‘learning_logs’), namespace=‘learning_logs’)),
]

‘’‘into c:\learning_log\learning_logs\urls.py I have’‘’

from django.urls import re_path as url2
from . import views

urlpatterns = [
# home page
url2(‘^$’, views.index, name=‘index’),

]

‘’’ I have my home page in c:\learning_log\learning_logs\template\learning_logs\index.html ‘’’

1 Like