为什么我要连接Django的图书馆?

2024-10-05 11:36:15 发布

您现在位置:Python中文网/ 问答频道 /正文

在app general of url中添加库路径时,向我发送下一条消息:“E0611:No name‘path’in module”django.url'和“E0611:模块中没有名称're\u path'”django.url'". 你知道吗

它是URL中的代码:

from django.contrib import admin
from django.urls import include,re_path
from django.urls import include,path
from homepage.views import homepage

urlpatterns = [
    path(r'^admin/', admin.site.urls),
    path(r'^',include('homepage.urls')),
]

urlpatterns +=[
    re_path(r'home/',include('homepage.urls'))
]

我使用的版本是v2.1

谢谢你帮我。你知道吗


Tags: ofpathdjangofromimportreappurl
1条回答
网友
1楼 · 发布于 2024-10-05 11:36:15

在官方文件中他们解释酷。你呢需要进一步研究文档吗

#Example of using re_path

from django.urls import include, re_path

urlpatterns = [
    re_path(r'^index/$', views.index, name='index'),
    re_path(r'^bio/(?P<username>\w+)/$', views.bio, name='bio'),
    re_path(r'^weblog/', include('blog.urls')),
    ...
] 

 #Example of using path

from django.urls import include, path

urlpatterns = [
    path('index/', views.index, name='main-view'),
    path('bio/<username>/', views.bio, name='bio'),
    path('articles/<slug:title>/', views.article, name='article-detail'),
    path('articles/<slug:title>/<int:section>/', views.section, name='article-section'),
    path('weblog/', include('blog.urls')),
    ...
]

文件:

  1. https://docs.djangoproject.com/en/2.1/ref/urls/#re-path
  2. https://docs.djangoproject.com/en/2.1/ref/urls/#path

相关问题 更多 >

    热门问题