Django管理。在Heroku上的py自定义命令

时间:2022-06-12 23:19:01

I am trying to run a cron job with a Heroku hosted website. I am using a Django back-end. I have written a custom manage.py command that works locally (status_crawl.py). I have seen a few guides and posts on how to fix this, but the suggestions did not work (such as Running Django custom manage.py task on Heroku - Importing Issues and this guide).

我正在尝试运行一个Heroku网站的cron工作。我正在使用Django后端。我写了一个自定义管理。本地工作的py命令(status_crawl.py)。我已经看到了一些关于如何修复这个问题的指南和文章,但是这些建议并没有起作用(例如运行Django自定义管理)。关于Heroku -导入问题的py任务和本指南)。

Even weirder is that it is recognizing the other commands. (And I managed to get the basic task to work by using runscript from the django-extensions framework). It is still bothering me though.

更奇怪的是,它正在识别其他命令。(通过使用来自django-extensions框架的runscript,我设法让基本的任务正常工作)。但它仍然困扰着我。

My basic file structure likes like:

我的基本文件结构如下:

 likes:
   ...
   management:
      __init__.py
      commands:
      __init__.py
      status_crawl.py

The traceback is:

回溯是:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named commands.status_crawl

The other weird thing is that when I run 'heroku run python manage.py help' the command is showing up as an option. It's just not running when I try to run the script myself using the manage.py command.

另一个奇怪的事情是,当我运行“heroku run python管理”时。py帮助'命令显示为选项。当我试图使用manage自己运行脚本时,它就不会运行。py命令。

Thanks!

谢谢!

1 个解决方案

#1


1  

Probably it's related to your PYTHONPATH variable on Heroku. This variable on Heroku may differ from your local PYTHONPATH. Try to import from the root of your project, like:

它可能与Heroku上的PYTHONPATH变量有关。Heroku上的这个变量可能与本地python路径不同。尝试从项目的根导入,比如:

from likes.management.commands import status_crawl

#1


1  

Probably it's related to your PYTHONPATH variable on Heroku. This variable on Heroku may differ from your local PYTHONPATH. Try to import from the root of your project, like:

它可能与Heroku上的PYTHONPATH变量有关。Heroku上的这个变量可能与本地python路径不同。尝试从项目的根导入,比如:

from likes.management.commands import status_crawl