Comments (3)
该类下
def get_serializer_class(self):
如果self.request.method.lower()=='get'
这里self下是没有请求属性的,运行报错。
可以修改为
类JobsListCreateViewSet(mixins.ListModelMixin,mixins.CreateModelMixin, GenericViewSet):
def get_serializer_class(self):
if self.action =='list':
返回JobsListSerializer
感谢提出问题
JobsListCreateAPIView继承rest_framework的ListCreateAPIView,最后仍然是继承的Django的View类。
get_serializer_class该方法,self是有request属性的,我这边并没有出现您提出的问题!运行未出现报错!
如您那边仍出现该问题,请提供错误详情,方便进行定位。
from drf_admin.
你好,我是添加了docs后,访问http://127.0.0.1:8080/docs/的时候报这个错的,AttributeError: 'NoneType' object has no attribute 'method',你可以试下
from drf_admin.
你好,我是添加了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)
- 【建议】在文档中指定要求的redis版本 HOT 2
- 【咨询问题】在项目任意文件中调试(debug)变量 HOT 3
- 联系求助 HOT 3
- 关于用户权限的实现 HOT 1
- 权限问题 HOT 2
- 大佬,快更新呀,感觉权限模块没有完全实现 HOT 2
- django_apscheduler 在 uwsgi 多进程环境下无法正常运行 HOT 2
- drf admin项目 QQ交流群
- ModuleNotFoundError: No module named 'easyaudit' HOT 1
- object-level / instance-level / row-level 权限控制 HOT 2
- 错误的代码放上了折腾好久 HOT 1
- 关于主机绑定部门问题 HOT 1
- 依赖包文件版本需更新 HOT 1
- 大佬诚招测开讲师,我的微信:18821768014,有意向我们可以聊下
- 权限问题 HOT 1
- 运行久了后端会报“took too long to shut down and was killed.”错误,导致连接异常
- 任务调度报错
- 资产管理无法显示 HOT 3
- 用户权限问题 HOT 1
- 【建议】在文档中指定python具体版本 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf_admin.