Home > Enterprise >  how include links from main urls.py file to model urls.py file?
how include links from main urls.py file to model urls.py file?

Time:06-13

I am trying to include links from a 'Post/urls.py' file, to 'blog/urls.py' (admin file) but I get an error message Do you hope to help solve this problem?

#Post/urls.py

from django.conf.urls import url
from . import views

    urlpatterns = [
        url(r'^$',views.all_posts, name='all_posts'),
        url(r'^(?P<id>\d )$',views.post, name='post'),
    ]

blog/urls.py

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('Post.urls', namespace ='blog')),
]

Error msg: from django.conf.urls import url ImportError: cannot import name 'url' from 'django.conf.urls' (C:\xampp\htdocs\django\blog\lib\site-packages\django\conf\urls_init_.py)

CodePudding user response:

django.conf.urls.url() was deprecated in Django 3.0, and is removed in Django 4.0 .

use path instead

#Post/urls.py

from django.urls import path
from . import views

    urlpatterns = [
        path('',views.all_posts, name='all_posts'),
        path('<id>',views.post, name='post'),
    ]
  • Related