Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Python Django文件字段未保存_Python_Django - Fatal编程技术网

Python Django文件字段未保存

Python Django文件字段未保存,python,django,Python,Django,这里有一些帖子和我的帖子处理同样的问题,但是没有一个能为我的问题提供合适的解决方案。 我正在从事一个有多种模型的项目,比如a、B、C、D和E。其中三种模型都有文件字段。我已更改settings.py MEDIA_ROOT和MEDIA_URL以使文件字段正常工作。它在两款车型上都能完美工作,并可保存到正确的位置和所有部件。对于第三个模型,相同的行 models.FileField( upload_to='media/documents', null=True, blank=True) 不将文件保

这里有一些帖子和我的帖子处理同样的问题,但是没有一个能为我的问题提供合适的解决方案。 我正在从事一个有多种模型的项目,比如a、B、C、D和E。其中三种模型都有文件字段。我已更改settings.py MEDIA_ROOT和MEDIA_URL以使文件字段正常工作。它在两款车型上都能完美工作,并可保存到正确的位置和所有部件。对于第三个模型,相同的行

models.FileField( upload_to='media/documents', null=True, blank=True)
不将文件保存到该位置。httpd错误日志为空。第三个模型是内联模型。任何人都知道为什么这个模型会突然“出故障”。以下是httpd访问日志

192.168.45.139 - - [06/Aug/2018:15:50:01 +0000] "POST /admin/midb/job/3027/change/ HTTP/1.1" 302 -
192.168.45.139 - - [06/Aug/2018:15:50:01 +0000] "GET /admin/midb/job/3027/change/ HTTP/1.1" 200 205520
192.168.45.139 - - [06/Aug/2018:15:50:03 +0000] "GET /nested_admin/server-data.js HTTP/1.1" 200 288
192.168.45.139 - - [06/Aug/2018:15:50:03 +0000] "GET /admin/jsi18n/ HTTP/1.1" 200 3185
编辑:添加模型。前两个“起作用”,而最后一个不起作用。前两个模型是独立的,而第三个模型是内联的。这将保存在Django admin中

class CustomerPDF(models.Model):
    author = models.CharField(blank=False, null=False, max_length=300)
    other_members = models.CharField(blank=True, null=True, max_length=250)
    institute = models.CharField(blank=True, null=True, max_length=300)
    cr_system = models.ForeignKey(
        Job, on_delete=models.CASCADE, blank=True, null=True)
    paper = models.CharField(blank=True, null=True, max_length=300)
    url = models.URLField(blank=True, null=True,
                          max_length=300)
    year = models.CharField(blank=True, null=True, max_length=150)
    journal = models.CharField(blank=True, null=True, max_length=300)
    tags = models.CharField(blank=True, null=True, max_length=200)
    file_pdf_customer = models.FileField(
        upload_to='media/documents', null=True, blank=True)
    file_pdf_customer.allow_tags = True

class MarketTrends(models.Model):
    author = models.CharField(blank=False, null=False, max_length=300)
    institute = models.CharField(blank=True, null=True, max_length=500)
    paper = models.CharField(blank=True, null=True, max_length=300)
    year = models.CharField(blank=True, null=True, max_length=15)
    tags = models.CharField(blank=True, null=True, max_length=200)
    file_pdf_market = models.FileField(
        upload_to='media/documents', null=True, blank=True)
    file_pdf_market.allow_tags = True

class TripReport(models.Model):
    service_name = models.ForeignKey(ServiceSupport, on_delete=models.CASCADE)
    trip_description = models.CharField(
        "Description", max_length=500, blank=True, null=True)
    files = models.FileField(
        upload_to='media/documents', null=True, blank=True)

您是否在模板中添加了这些代码

<form  method="post" id="myform"  enctype="multipart/form-data">

您是否在模板中添加了这些代码

<form  method="post" id="myform"  enctype="multipart/form-data">


你能将这些模型添加到帖子中吗?你在哪里上传?在管理中,还是单独的页面?如果是这样,请发布相关视图、表单和模板。注意,尽管上传位置通常不需要“媒体”。@JerinterGeorge我添加了模型,但我不确定这是否有帮助:(@DanielRoseman这是在管理员中完成的。你能将这些模型添加到帖子中吗?你在哪里上传?在管理员中,或者在单独的页面中?如果是这样,发布相关的视图、表单和模板。注意,尽管你通常不需要上传到位置中的“媒体”。@JerinterGeorge我添加了模型,但我不确定这是否有帮助:(@DanielRoseman)这是在管理员中完成的。