Giter Club home page Giter Club logo

Comments (3)

TianPangJi avatar TianPangJi commented on June 7, 2024

该类下
def get_serializer_class(s​​elf):
如果self.request.method.lower()=='get'
这里self下是没有请求属性的,运行报错。
可以修改为
类JobsListCreateViewSet(mixins.ListModelMixin,mixins.CreateModelMixin, GenericViewSet):
def get_serializer_class(s​​elf):
if self.action =='list':
返回JobsListSerializer

感谢提出问题
JobsListCreateAPIView继承rest_framework的ListCreateAPIView,最后仍然是继承的Django的View类。
get_serializer_class该方法,self是有request属性的,我这边并没有出现您提出的问题!运行未出现报错!
如您那边仍出现该问题,请提供错误详情,方便进行定位。

from drf_admin.

hzyddhuang avatar hzyddhuang commented on June 7, 2024

你好,我是添加了docs后,访问http://127.0.0.1:8080/docs/的时候报这个错的,AttributeError: 'NoneType' object has no attribute 'method',你可以试下

from drf_admin.

TianPangJi avatar TianPangJi commented on June 7, 2024

你好,我是添加了docs后,访问http://127.0.0.1:8080/docs/的时候报这个错的,AttributeError:“ NoneType”对象没有属性“ method”,你可以试下

我这边并没有使用内置的API文档,而是使用的drf-yasg;

但也看了下你提出的这个问题,这个问题在DRF官方文档已给出了解释:
Note: By default include_docs_urls configures the underlying SchemaView to generate public schemas. This means that views will not be instantiated with a request instance. i.e. Inside the view self.request will be None.
To be compatible with this behaviour, methods (such as get_serializer or get_serializer_class etc.) which inspect self.request or, particularly, self.request.user may need to be adjusted to handle this case.
You may ensure views are given a request instance by calling include_docs_urls with public=False

DRF官方链接
个人建议不修改继承类,而是添加public属性。

from drf_admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.