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在上载Python文件时遇到问题_Python_Django_Python 3.3 - Fatal编程技术网

Django在上载Python文件时遇到问题

Django在上载Python文件时遇到问题,python,django,python-3.3,Python,Django,Python 3.3,到目前为止,我的代码是: from django.core.files import File file = open('ChicagoTimesScores.py') djangofile = File(file) myfile = File(file) myfile.save('new', djangofile) file.close() 我知道会重复我的文件,但我有点迷路了,试着看看它是否有效 我的错误代码: Traceback (most recent call last): F

到目前为止,我的代码是:

from django.core.files import File

file = open('ChicagoTimesScores.py')
djangofile = File(file)
myfile = File(file)
myfile.save('new', djangofile)
file.close()
我知道会重复我的文件,但我有点迷路了,试着看看它是否有效

我的错误代码:

Traceback (most recent call last):
  File "C:/Python33/TestRun.py", line 6, in <module>
    myfile.save('new', djangofile)
AttributeError: 'File' object has no attribute 'save'
回溯(最近一次呼叫最后一次):
文件“C:/Python33/TestRun.py”,第6行,在
保存('new',djangofile)
AttributeError:“文件”对象没有属性“保存”
我试图用django保存这个python文件,但python似乎无法识别这些属性


哦,是的,我正确安装了django。没有问题。

Django文件类没有“保存”方法这里是文件类的Django文档:


你想做什么?根据
文件
只有一个
保存
方法,如果它与一个对象相关联。我正试图通过ORM将Django连接到Python。也许我的标题不正确,不仅仅是标题。您的
myfile
与对象没有关联,因此它没有
save
方法。但是我不认为没有人能在不知道你最终目标的情况下帮助你。保罗已经解释了你为什么会犯错<代码>文件对象通常在模型字段(如FileField)中使用。也许从