1

这是一个简单的django模型:

class File(models.Model):
    info = models.CharField(max_length=150,null=True,blank=True)
    slug = models.SlugField(max_length=50, blank=True)
    file = models.FileField(upload_to="files")

我想保存任何实例,以便文件的文件名是波斯文件名。这是我的观点:

class FileCreateView(CreateView):
    model = File

    def form_valid(self, form):
       self.object = form.save()
        f = self.request.FILES.get('file')
        files = [{
          'url': self.object.file.url,
          'name': self.object.file.url[6:],
          'thumbnailUrl': self.object.file.url,
          'info' : self.object.info,
          'size': f.size,
          'deleteUrl': reverse('upload-delete', args=[self.object.id]),
          'deleteType': "DELETE",
        }]
        data = {"files": files}
        response = JSONResponse(data, {}, response_mimetype(self.request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response

但是当我想上传一个波斯名字的新文件时,我看到这个错误:

SyntaxError: Unexpected token

感谢你 :)

4

0 回答 0