Django 管理任务在 CentOS 上的 crontab 或外部项目目录中不起作用
在我的本地计算机(Mac OSX 10.6)上,我编写了一个 django 自定义管理命令,效果很好。我可以在项目目录内部和外部使用它。由于某种原因,在我的 CentOS 5.6 服务器上,它无法在项目目录之外运行。这真的很烦人,因为在 cron 作业中使用这个自定义管理命令需要它从主目录运行。
简而言之:
当我运行“python ./manage.py scrape”或“python manage.py scrape”时,一切都很好。
当我运行“python /home/[username]/webapps/myproject/manage.py scrape”或“python myproject/manage.py scrape”时,出现以下错误:
未知命令:'scrape'
输入“manage.py help”以了解用法。
在CentOS上,当我在项目目录中运行manage.py help时,scrape会显示为命令;但如果我在项目目录之外运行它,则 scrape 不会显示为有效命令。在 OS-X 上,无论我从何处运行 manage.py help,scrape 都会显示为有效命令。
知道我该如何解决这个问题吗?
On my local machine (Mac OSX 10.6) I wrote a django custom admin command which works great. I can use it both within and outside my project directory just fine. For some reason on my CentOS 5.6 server, it won't work from outside the project directory. This is really annoying since using this custom admin command in a cron job requires it to run from the home directory.
in short:
When I run "python ./manage.py scrape" or "python manage.py scrape", everything is fine.
When I run "python /home/[username]/webapps/myproject/manage.py scrape" or "python myproject/manage.py scrape", I get the following error:
unknown command: 'scrape'
Type 'manage.py help' for usage.
On CentOS, when I run manage.py help inside the project directory, scrape shows up as a command; but if I run it outside the project directory, scrape does not appear as a valid command. On OS-X scrape appears as a valid command regardless of where I run manage.py help from.
Any idea how I can fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道 CentOS 附带 Python 2.4,所以您的代码是在 2.4 上运行还是您使用的是封闭环境,这通常可以通过正确添加 PYTHONPATH 来修复
,对于初学者进行验证
I know CentOS ships with Python 2.4, so is your code running on 2.4 or are you using a contained environment, this is usually fixed by adding your PYTHONPATH correctly
verify such for starters
这应该可以让您启动并运行:http://djangosnippets.org/snippets/374/
This should get you up and running: http://djangosnippets.org/snippets/374/