django - Django 无法解析 url 路径 404
问题描述
嗨,我对 django 有一个非常烦人的问题:我设置了许多 url 路径,除了一个之外它们都工作正常,我真的不知道为什么:
网址
urlpatterns = [
# path('foods/search', food_search),
path('food_list/',
FoodListVersionListCreateAPIView.as_view(),
name='foodList-list'),
path('all_foods/<str:survey>/<str:string>',
FoodListCreateAPIView.as_view(),
name='food-list'),
path('food_classification/',
FoodClassificationListCreateAPIView.as_view(),
name='foodClassification-list'),
path('food/<str:survey>/<str:string>/',
FoodDetailAPIView.as_view(),
name='food-detail'),
]
意见
class FoodListCreateAPIView(generics.ListCreateAPIView):
queryset = Food.objects.all()
serializer_class = FoodSerializer
filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_fields = ['description', 'food_code',
'cofid_code', 'foodex_code',
'food_classification']
search_fields = ['food_list', 'SYSTEM_TIME']
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
def get_queryset(self):
assert self.queryset is not None, (
"'%s' should either include a `queryset` attribute, "
"or override the `get_queryset()` method."
% self.__class__.__name__
)
survey = self.request.query_params['survey']
food = self.request.query_params['string']
raw_queryset = perform_food_search(survey, food)
queryset = Food.objects.filter(pk__in=[i.pk for i in raw_queryset])
if isinstance(queryset, QuerySet):
# Ensure queryset is re-evaluated on each request.
queryset = queryset.all()
return queryset
错误信息
解决方案
推荐阅读
- r - KableExtra + R 调整标题(字体、大小、颜色等...)
- angular - 在不捆绑的情况下检查 Angular 应用程序的模板错误
- excel - 如何创建一个 excel 文件并通过每次新运行添加一行新的输出数据来更新它?
- python - “AttributeError: module 'wx' has no attribute 'adv'” 尽管 Phoenix
- css - CSS(动作选择器):目标不起作用
- python - 显示导致测试失败的数组条目
- android - 如何通过启动我的应用程序的意图移动到 OPPO 的应用程序信息页面?
- selenium - python'lxml'解析html,通过xpath获取数据不起作用
- c - 如何使用 C 将信号从父进程发送到子进程?
- geolocation - 如何禁用鹦鹉操作系统中的所有定位服务?