【发布时间】:2015-06-26 11:11:30
【问题描述】:
我有一个 Django 应用程序在 Heroku 上运行。我想运行一个名为 import.py 的简单脚本,它将一个 CSV 文件导入到我的模型中。它在我的本地计算机上运行良好。当我尝试使用此命令在 Heroku 上运行脚本时:
heroku run python manage.py < import.py
它所做的只是将脚本读回给我,但不执行任何内容。我做错了什么?
编辑:
这是我运行时得到的结果的开始:heroku run python manage.py
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import csv
>>> from bah_api.models import withDependents, withOutDependents, ZipMHA
>>>
>>> # Populate CSV file into model
>>> def LoadCSV(file_location, my_model, delim):
... f = open(file_location)
File "<console>", line 2
f = open(file_location)
^
IndentationError: expected an indented block
>>> csv_f = csv.reader(f, delimiter=delim)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'f' is not defined
>>> for row in csv_f:
...
Display all 182 possibilities? (y or n)
【问题讨论】:
-
不应该是
heroku run python manage.py shell < import.py吗? -
我刚试过。似乎 shell 正在尝试逐行运行文件。但它没有显示与文件中相同的缩进。