【问题标题】:when going to admin giving error site url does not exist当去管理员给出错误站点网址不存在时
【发布时间】:2021-12-31 17:43:03
【问题描述】:

当我尝试进入管理路径时,它给了我一个错误,说站点匹配查询不存在,这在我之前从未发生过

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('allauth.urls')),
    path('', include('core.urls', namespace='core'))
]

这是我的主要项目网址

from django.urls import path
from .views import (
    ItemDetailView,
    CheckoutView,
    HomeView,
    OrderSummaryView,
    add_to_cart,
    remove_from_cart,
    remove_single_item_from_cart,
    PaymentView,
    AddCouponView,
    RequestRefundView
)

app_name = 'core'

urlpatterns = [
    path('', HomeView.as_view(), name='home'),
    path('checkout/', CheckoutView.as_view(), name='checkout'),
    path('order-summary/', OrderSummaryView.as_view(), name='order-summary'),
    path('product/<slug>/', ItemDetailView.as_view(), name='product'),
    path('add-to-cart/<slug>/', add_to_cart, name='add-to-cart'),
    path('add-coupon/', AddCouponView.as_view(), name='add-coupon'),
    path('remove-from-cart/<slug>/', remove_from_cart, name='remove-from-cart'),
    path('remove-item-from-cart/<slug>/', remove_single_item_from_cart,
         name='remove-single-item-from-cart'),
    path('payment/<payment_option>/', PaymentView.as_view(), name='payment'),
    path('request-refund/', RequestRefundView.as_view(), name='request-refund')
]

我的应用网址

【问题讨论】:

    标签: django django-models django-views django-forms django-templates


    【解决方案1】:

    这很可能与您的urls 有关。请仔细检查您是否在 url 中包含了管理路由,并确保没有路径冲突。如需更多帮助,您应该将您的网址代码或设置粘贴到您认为可能出现错误的位置。

    这是供参考的管理路径:

    from django.contrib import admin
    
    urlpatterns = [path("admin/", admin.site.urls)]
    

    【讨论】:

    • 我已经用网址编辑了问题
    • 尝试在 django 中添加 django.contrib.sites INSTALLED_APPS 并在您的 django 设置文件中添加 SITE_ID=1
    • 添加 site_is=1 有效,但你能解释为什么会发生这种情况改进答案,我会接受这个谢谢你
    • SITE_ID 表示您在数据库表中创建一个对象,您将在其中根据您的应用程序(如 apple.com)添加站点名称。如果您需要更多信息,这里是参考,希望对您有所帮助!(docs.djangoproject.com/en/3.1/ref/contrib/sites/…)
    猜你喜欢
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多