【发布时间】:2011-06-18 08:41:40
【问题描述】:
我可以移动到 python 项目目录(比如 c:\www\myproject)然后发出
python manage.py shell
然后我可以使用 django 项目中的所有模块,从 shell 命令中说出以下命令:
import settings
from django.template import Template, Context
t=Template("My name is {myname}.")
c=Context({"myname":"John"})
f = open('write_test.txt', 'w')
f.write(t.render(c))
f.close
现在,当我尝试将所有命令收集到 python 脚本中时,例如“mytest.py”,我无法执行该脚本。我一定错过了一些重要的事情。
我发布了python mytest.py
然后我得到Import error: could not import settings 它在系统路径上吗?”
我在settings.py所在的项目目录中.....
有人能帮帮我吗?
谢谢。
【问题讨论】:
-
你能发布错误吗?您很可能遇到了 PYTHONPATH 问题。由于您的问题提到了 C: 驱动器,我假设您在 Windows 上。 docs.python.org/using/windows.html