首页 > 解决方案 > 我在 django 的动态 urls 系统中有问题

问题描述

我一直在关注 youtube 上关于构建某种项目的其他教程。几天来试图找到问题的解决方案

我尝试使用'str'和'int'

from django.urls import path
from . import views


urlpatterns = [
    path('', views.home),
    path('products/', views.products),
    path('customer/<int:my_id>/', views.customer),
]

这是我在views.py中的代码


def customer(request, my_id):
    customer = Customer.objects.get(id=my_id)
    orders = customer.order_set.all()

    context = {'customer': customer, 'orders': orders}
    return render(request, 'accounts/customer.htm', context)

请帮忙

标签: django-modelsdjango-views

解决方案


推荐阅读