html文件url在django中不可访问

问题描述 投票:0回答:1

register.html在'register /'url上不可访问

尝试将URL更改为”,并且可以访问网页,但无法在“ register /”上进行访问

项目urls.py

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

urlpatterns = [
    path('login/',include('login.urls')),
    path('admin/', admin.site.urls),
]

apps urls.py

 from django.urls import path
from . import views

urlpatterns = [
    path('',views.indexView, name = "home"),
    path('dashboard/', views.dashboardView, name="dashboard"),
    #path('login/',),
    path('register/',views.registerView, name="register_url"),
    #path('logout/',),
]

views.py

 from django.shortcuts import render

def indexView(request):
    return render(request,'index.html')

def dashboardView(request):
    return render(request,'dashboard.html')

def registerView(request):
    return render(request,'register.html')

templates / register.html

python django django-urls
1个回答
0
投票

您应在主urls.py中添加应用程序urls.py的url映射这可能会对您有所帮助。

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


urlpatterns = [
    path('',include('apps.urls')), #put you app name here
    path('admin/', admin.site.urls),
]

apps urls.py

 from django.urls import path
from . import views

urlpatterns = [
    path('',views.indexView, name = "home"),
    path('dashboard/', views.dashboardView, name="dashboard"),

    path('register/',views.registerView, name="register_url"),

]

这将起作用,您可以在应用程序urls.py中添加登录名/网址映射。这种类型的流将使其易于理解。

© www.soinside.com 2019 - 2024. All rights reserved.