这是app urls.py文件的代码。
from django.urls import path
from blog import views
urlpatterns = [
path('',views.PostListView.as_view(),name='post_list'),
# sets home page to all current blogs that are published
path('about/',views.AboutView.as_view(),name='about'),
path('post/<int:pk>',views.PostDetailView.as_view(),name='post_detail'),
# will match primary key to whatever we click on
path('post/new/',views.CreatePostView.as_view(),name='post_new'),
path('post/<int:pk>/edit/',views.PostUpdateView.as_view(),name='post_edit'),
path('post/<int:pk>/remove/',views.PostDeleteView.as_view(),name='post_remove'),
path('drafts/',views.DraftListView.as_view(),name='post_draft_list'),
path('post/<int:pk>/comment/',views.add_comment_to_post,name='add_comment_to_post'),
path('comment/<int:pk>/approve',views.comment_approve,name='comment_approve'),
path('comment/<int:pk>/remove',views.comment_remove,name='comment_remove'),
path('post/<int:pk>/publish',views.post_publish,name='post_publish'),
]
这是网站urls.py文件的代码。
from django.urls import path,include
from django.contrib import admin
from django.contrib.auth import views # just importing some prefab views for authorization
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('blog.urls')),
# path('accounts/login',views.login,name='login'),
path('accounts/login',views.LoginView.as_view(),name='login'),
path('accounts/logout',views.LoginView.as_view(),name='logout',kwargs={'next_page':'/'}),
# so when you logout, the next page you go to is the home page
]
请大家帮忙!谢谢!这是我从浏览器收到的错误。
这是因为你没有任何带有'accountsprofile'的URL。检查你是否忘记在你的urls文件中包含视图。
我发现了这个错误。我在settings.py文件中的LOGIN_REDIRECT_URL = ''语句中出现了一个错别字,所以默认情况下,它试图转到我的个人资料页(不存在)而不是我的主页。