why we create polls/urls.py module in app directory even we can do the whole thing in project's mysite/urls.py?
在我的投票/urls.py中的以下代码
从django.urls导入路径从。导入视图
1 2 3 4 5 6 7 8 | urlpatterns = [ path('', views.index), # name='whatever_name' path('<int:question_id>/', views.detail, name='detail'), path('<int:question_id>/results', views.results, name='result'), path('<int:question_id>/vote', views.vote, name= 'vote'), |
]
然后我删除了文件,并在mysite/urls.py中添加了所有内容,mysite/urls.py是根urls模块,它工作正常。
1 2 3 4 5 6 7 8 9 10 | from django.contrib import admin from django.urls import path,include from polls import views urlpatterns = [ path('polls/', views.index, name='index'), path('polls/<int:question_id>/', views.detail, name='detail'), path('polls/<int:question_id>/results/', views.results, name='result'), path('polls/<int:question_id>/vote/', views.vote, name= 'vote'), path('admin/', admin.site.urls), |
号
]
是的,将URL放在根目录