为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

开满天机 2021-12-21 16:25:29
在这个 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但如果我手动输入链接工作正常。视图.pyfrom django.http import HttpResponsefrom 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 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')),    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')),]
查看完整描述

1 回答

?
万千封印

TA贡献1891条经验 获得超3个赞

您应该include('formfiller.urls')只使用一次。


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')),

]


查看完整回答
反对 回复 2021-12-21
  • 1 回答
  • 0 关注
  • 169 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信