Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django save()为关键字参数';获取了多个值;最大长度';_Django_File Upload - Fatal编程技术网

Django save()为关键字参数';获取了多个值;最大长度';

Django save()为关键字参数';获取了多个值;最大长度';,django,file-upload,Django,File Upload,我使用的是django的save方法,错误是save()为关键字参数“max\u length”获取了多个值。 这是我的模型: def generate_path(instance, filename): section=instance.document_title.historical_set.last().id_section year=str(section.year.number) course=(section.course.name) sec

我使用的是django的save方法,错误是
save()为关键字参数“max\u length”获取了多个值。

这是我的模型:

def generate_path(instance, filename):
     section=instance.document_title.historical_set.last().id_section
     year=str(section.year.number)
     course=(section.course.name)
     section=str(section.number)
     curso=curso.encode('utf-8').decode('utf-8')
     return os.path.join(ciclo,curso,seccion,filename)


class UseExistingStorage(FileSystemStorage):

   def save(name, content, max_length=None):
       if not self.exists(name):
           return super().save(self,name, content, max_length)
       return name

class Field(models.Model):
     type=models.CharField(max_length=50, choices=document_type, default=None)
     document_title=models.ForeignKey(Document,on_delete=models.CASCADE,null=True)
     file = models.FileField(null=True,blank=True,     upload_to=generate_path,storage=UseExistingStorage())
     rubric=models.FileField(null=True,blank=True,upload_to=generate_path,storage=UseExistingStorage())
这就是我保存字段的方式:

if FieldForm.is_valid():
  course=request.POST.get('course')
  coursename=Course.objects.values('name').get(name=course)

  try:
       field.file=request.FILES['file']

  except:
        pass
  try:
       field.rubric=request.FILES['rubric']

  except:
       pass
  if type.find('a')!=-1:
       field.type='a'
  elif coursename.find('b')!=-1 :
       field.type='b'
  elif type.find('c')!=-1:
       field.type='c'
  else:
       field.type='d'

  field.document_title=documentTitle
  field.save()

在生成路径中,我在年份/课程/章节中保存文档的路径,并在存储中检查该字段是否存在于该位置。但我不知道为什么会出现此错误

您不需要显式传递
self
super()
将为您执行此操作,请尝试以下操作:

return super().save(name, content, max_length)
而不是

return super().save(self,name, content, max_length)
另外,重写
save()
的第一个参数也应该是
self

def save(self, name, content, max_length=None):
   if not self.exists(name):
       return super().save(name, content, max_length)
   return name
UPD

对于python2,您应该将
self
class
作为super的参数传递:

return super(UseExistingStorage, self).save(name, content, max_length)

现在我得到了这个错误,
super()至少接受一个参数(给定0)
,我使用的是python 2.7和django 1。11@Mecha对于python2,您应该使用带有参数的
super()
。请参阅更新。