亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復頁面未找到(404)錯誤django2.0的個人資料頁面

如何修復頁面未找到(404)錯誤django2.0的個人資料頁面

神不在的星期二 2022-10-18 14:58:08
如何修復頁面未找到(404)錯誤django2.0的個人資料頁面這段代碼查看代碼'''def profile(request, slug):    profile = Profile.objects.get(slug=slug)    context = {        'profile':profile,    }    return render(request, 'registration/profile.html' ,context)''' 和這個 urls.py'''from django.urls import path,re_pathfrom . import viewsfrom django.contrib.auth.views import LoginView,logout #login app_name='accounts'urlpatterns = [    path(r'', views.home, name ='home'),    # path(r'^login/$', login, {'template_name':'registration/login.html'}),    path('login/', LoginView.as_view(), name="login"),    path(r'^logout/$', logout, name='logout'),    # path(r'^signup/$', views.register, name='register'),    path('signup/', views.register, name='signup'),    path(r'^(?P<slug>[-\w]+)/$', views.profile, name='profile'),     # path(r'^(?P<slug>[-\w]+)/edit$', views.edit_profile, name='edit_profile'),]'''模板/注冊文件夾中的 profile.html 頁面
查看完整描述

1 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

如果您正在使用,path()那么您不應該使用像r'^logout/$'and之類的正則表達式r'^(?P<slug>[-\w]+)/$。


替換以下兩個 URL 模式


path(r'^logout/$', logout, name='logout'),

path(r'^(?P<slug>[-\w]+)/$', views.profile, name='profile'),

用這些:


path('logout/', logout, name='logout'),

path('<slug:slug>/', views.profile, name='profile'),


查看完整回答
反對 回復 2022-10-18
  • 1 回答
  • 0 關注
  • 78 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號