【问题标题】:Django error : Fix your URL conf, or set the `.lookup_field` attribute on the view correctlyDjango 错误:修复您的 URL 配置,或正确设置视图上的 `.lookup_field` 属性
【发布时间】:2020-09-19 11:42:46
【问题描述】:

我在views.py中定义了这个类:

class EditOrderStudents(generics.RetrieveUpdateDestroyAPIView):

    #permission_classes = (permissions.AllowAny,)
    authentication_classes = (TokenAuthentication , )
    serializer_class =newOrdersStudentSerializidGet

    def get_queryset(self):

        id = self.request.query_params.get('id')
        queryset = newOrdersStudent.objects.filter(Groupid=(id))
        return queryset

我使用RetrieveUpdateDestroyAPIView 泛型来放置、删除和获取方法

但是我得到了这个错误,我不知道是什么问题?

AssertionError: Expected view EditOrderStudents to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.

【问题讨论】:

    标签: python django


    【解决方案1】:

    在您的 URL 配置中使用它,

    path('edit/<int:pk>/', EditOrderStudents.as_view(), name='edit')
    

    运行您的应用并转到http://127.0.0.1:8000/edit/1/

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 2011-08-05
      • 2022-06-18
      • 1970-01-01
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多