【发布时间】:2022-10-18 16:39:10
【问题描述】:
当我在 URL 中传递 id 时出现此错误。
请检查我的以下代码。
引用 URL 作为模板中的链接:
<a href="{% url 'he_admin:viewcategory' pk=category.id %}" class="btn btn-outline-info" title="View" ><i class="far fa-eye"></i></a>
网址模块:
from django.contrib import admin
from django.urls import path
from he_admin import views
app_name='he_admin'
urlpatterns = [
path('',views.index,name='index'),
path('addproductscategory',views.add_products_category,name='addcategory'),
path('showcategories',views.ShowCategory,name='showcategories'),
path('view/<int:pk>',views.ViewCategory,name='viewcategory'),
]
查看功能:
def ViewCategory(request, pk):
try:
category=ProductCategory.objects.get(id=pk)
except:
raise Http404('category does not exist')
return render(request,"viewcategory.html",{"category":category})
错误:
【问题讨论】:
-
您能否在实际使用此 URL 的位置添加代码。
-
解决了 html <head >section <link rel="stylesheet" href="{%static 'css/adminlte.min.css' %}"> <link rel="stylesheet" href="{% static 'plugins/overlayScrollbars/css/OverlayScrollbars.min.css' %}"> <link rel="stylesheet" href="{%static 'plugins/daterangepicker/daterangepicker.css' %}">
标签: python django django-templates