【问题标题】:Path / URL error in application created for Django/Python course I'm taking为我正在学习的 Django/Python 课程创建的应用程序中的路径/URL 错误
【发布时间】:2020-08-16 13:21:21
【问题描述】:

This is the error I receive from the browser

这是应用程序 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
]

请帮忙!谢谢!

【问题讨论】:

    标签: python django url path


    【解决方案1】:

    这是因为您没有任何带有“帐户/个人资料”的网址。检查您是否忘记在 urls 文件中包含视图。

    【讨论】:

    • 谢谢。这通常是合乎逻辑的,但我没有个人资料页面。请参阅下面我自己的答案。再次感谢!
    • 我投了赞成票,但显然它不会显示,因为你或我的投票数少于 15。打勾是什么?抱歉,我是 SO 新手,还在学习礼仪。
    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 2016-05-06
    • 1970-01-01
    • 2011-06-25
    相关资源
    最近更新 更多