当使用类继承时,Python 3 报错 super()的第一个参数必须是类型,而不是WSGIRequest
。
我使用的是 Django 2.1.4 和 Python 3.7.0。我正在尝试查看用户是否已经提交了要分析的文件,如果没有,则将其重定向到提交页面。我尝试过不使用静态方法,检查它是否真的是 Python 3(因为此问题在 Python 2 上很常见),在超类中,我尝试从“object”继承,同时也从 Django 提供的“View”继承(因为这可以解决在 Python 2 中的问题:super() argument 1 must be type, not None)。
这是超类,它继承自 Django 提供的“View”类。
class DatasetRequired(View):
@staticmethod
def get(request):
<redirects the user>
这是基础类
class Estatisticas(DatasetRequired):
@staticmethod
def get(request):
super(request)
<do various other stuff>
我期望当调用基类的
get
函数时,会调用超类的 get
函数,并检查用户是否已经提交了文件。我理解:
TypeError at /estatisticas super() argument 1 must be type, not WSGIRequest
get()
返回结果并且不想忽略该结果,则新的.get()
方法应该使用该结果。 - Martijn Pieters