Django中的url冲突

时间:2018-02-25 19:46:47

标签: django url

无论我使用什么网址,我都会获得相同的网页。我得到了我列出的所有主页的home.html页面。任何建议都很有价值。谢谢!

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^signup/', include('log.urls')),
    url(r'^login/', include('log.urls')),
    url(r'^logout/', include('log.urls')),
    url(r'^', include('log.urls')),
]

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

# We are adding a URL called /home
urlpatterns = [
    url(r'^signup/', views.signup, name='signup'),
    url(r'^login/', views.login, name='login'),
    url(r'^logout/', views.logout, name = 'logout'),
    url(r'^', views.home, name='home'),
]

1 个答案:

答案 0 :(得分:2)

您的模式错误,包括log.urls在内的所有内容。它应该是

项目urls.py

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

然后,

log urls.py

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

urlpatterns = [
    url(r'^signup/$', views.signup, name='signup'),
    url(r'^login/$', views.login, name='login'),
    url(r'^logout/$', views.logout, name = 'logout'),
    url(r'^$', views.home, name='home'),
]