猿问

如何解决此 URL 映射问题?页面正在显示,但网址不正确

在这个 django 应用程序中,我试图转到特定页面,但它所走的路线不是正确的。你能告诉我我做错了什么吗?


前任。从http://127.0.0.1:8000我试图去http://127.0.0.1:8000/register但它把我带到http://127.0.0.1:8000/dashboard/register。


该http://127.0.0.1:8000/register但如果我手动输入链接工作正常。


视图.py


from django.http import HttpResponse

from django.shortcuts import render


# Create your views here.


def home(request):

    return render(request, 'formfiller/home.html')


def register(request):

    return render(request, 'formfiller/signup.html')


def login(request):

    return render(request, 'formfiller/login.html')


def download(request):

    return render(request, 'formfiller/download.html')


def forgotpw(request):

    return render(request, 'formfiller/forgotpw.html')


def learnmore(request):

    return render(request, 'formfiller/learnmore.html')


def dashboard(request):

    return render(request, 'formfiller/dashboard.html')


def success(request):

    return HttpResponse("Your account has been successfully created.")

urls.py(用于应用程序)


from django.urls import path

from . import views


urlpatterns = [

    path('', views.home, name='home'),

    path('register', views.register, name='signup'),

    path('login', views.login, name='login'),

    path('download', views.download, name='download'),

    path('forgotpw', views.forgotpw, name='forgotpw'),

    path('learnmore', views.learnmore, name='learnmore'),

    path('dashboard', views.dashboard, name='dashboard'),

    path('success', views.success, name='success'),

]

urls.py(用于主项目)


from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path('admin/', admin.site.urls),

    path('', include('formfiller.urls')),

    path('register/', include('formfiller.urls')),

    path('login/', include('formfiller.urls')),

    path('download/', include('formfiller.urls')),

    path('forgotpw/', include('formfiller.urls')),

    path('learnmore/', include('formfiller.urls')),

        path('success/', include('formfiller.urls')),

        path('dashboard/', include('formfiller.urls')),

]


开满天机
浏览 170回答 1
1回答

万千封印

您应该include('formfiller.urls')只使用一次。urls.py(用于应用程序)from django.urls import pathfrom . import viewsurlpatterns = [    path('', views.home, name='home'),    path('register', views.register, name='signup'),    path('login', views.login, name='login'),    path('download', views.download, name='download'),    path('forgotpw', views.forgotpw, name='forgotpw'),    path('learnmore', views.learnmore, name='learnmore'),    path('dashboard', views.dashboard, name='dashboard'),    path('success', views.success, name='success'),]urls.py(用于主项目)from django.contrib import adminfrom django.urls import path, includeurlpatterns = [    path('admin/', admin.site.urls),    path('', include('formfiller.urls')),]
随时随地看视频慕课网APP

相关分类

Python
我要回答