如何修復頁面未找到(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'),
添加回答
舉報
0/150
提交
取消