【问题标题】:wrong file path when uploading a file in django在django中上传文件时错误的文件路径
【发布时间】:2016-02-25 20:23:44
【问题描述】:

我的文件有以下模型:

class Import(models.Model):
     file = models.FileField(upload_to='%Y/%m/%d')

我这样保存它们:

f = request.FILES['import']
if f.size < settings.MAX_UPLOAD_SIZE:
    x = Import.objects.create(file=f)

我的媒体根目录:

MEDIA_ROOT = os.path.join('/home/xyz/project/main', 'upload/')

问题是,当我检查我的 x 对象时:

print x.file.path

它将返回“/home/my-computer-name/...”而不是“/home/xyz/...”。 我究竟做错了什么? Django 1.8,Ubuntu。 文件已上传到正确的路径。

【问题讨论】:

  • 您使用的是 Windows 还是 Linux?
  • 我在 Linux 上,ubuntu。
  • main 是我的项目的名称。它包含manage.py
  • 你试过我告诉你的方法了吗?这对您的项目有效吗?

标签: python django django-file-upload


【解决方案1】:

好吧,算了。我只是在打印路径时输入了错误的设置文件

【讨论】:

    猜你喜欢
    • 2020-10-13
    • 2017-02-20
    • 2010-12-31
    • 2011-04-07
    • 2012-05-18
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多