Django自定义命令不会显示在Heroku上 [英] Django custom commands not showing up on Heroku

查看:103
本文介绍了Django自定义命令不会显示在Heroku上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Heroku上使用django自定义命令时,我遇到问题。
在我的本地机器上,如果我运行./manage.py帮助并运行./manage.py deletedphotos也会在帮助中显示自定义命令。
所有的 init .py文件在那里,设置也是正确的,即我的本地和Heroku实例之间​​没有主要的配置差异。



现在,当我把它放在Heroku上时,它不会出现。我所有其他的非默认命令都是:来自安装sitemap.xml支持的ping_google和用于南迁的命令。但是由于某种原因,我自己写的命令不会出现。



我还向Heroku发送了一个支持请求,但没有从他们那里听到几天,所以我以为我也会发布在这里,也许有人有任何类似的问题。



deletephotos.py文件内容几乎是这样的,如果那任何事情:

  from django.core.management.base import BaseCommand,CommandError 
from foo.app.models import

class Command(BaseCommand):
help ='从S3删除照片

def handle(self,* args,** options):
deleted_photos = Photo.objects.filter(deleted = True).exclude(large ='',small ='',thumb ='')
self.stdout.write('Found%s photos\\\
'%str(len(deleted_photos)))

我已经尝试检查所有正确的python路径等,但不能100%,如果我没有缺少一些明显的东西。

解决方案

我实际上能够找到一个解决方案。 INSTALLED_APPS有我的本地应用程序被引用,但由于某些原因它没有按预期工作。



我的应用程序位于:/ name / appname /并具有'name.appname INSTALLED_APPS在本地设置中正常工作。



然而,在Heroku上,我不得不将INSTALLED_APPS中的引用改为appname,所有这些都开始神奇地工作。 / p>

I’m having a problem when using django custom commands on Heroku. On my local machine, the custom command appears in help if I run ./manage.py help and running ./manage.py deletedphotos runs it too. All the init.py files are there and the settings are also correct, i.e. there are not major config differences between my local and Heroku instances.

Now, when I put it on Heroku, it does not show up. All my other non-default commands are there: ping_google that comes from installing sitemap.xml support and commands for south migrations. But for some reason, my self written commands do not show up.

I’ve also sent a support request to Heroku, but haven’t heard back from them in a few days, so I thought I’d post here as well, maybe someone has had any similar problems.

The deletedphotos.py file contents are pretty much like this if that matters anything:

from django.core.management.base import BaseCommand, CommandError
from foo.app.models import *

class Command(BaseCommand):
    help = 'Delete photos from S3'

    def handle(self, *args, **options):
        deleted_photos = Photo.objects.filter(deleted=True).exclude(large='', small='', thumb='')
        self.stdout.write('Found %s photos\n' % str(len(deleted_photos)))

I’ve tried checking all the correct python paths etc, but not 100% if I’m not missing something obvious.

解决方案

I was actually able to find a solution. The INSTALLED_APPS had my local app referenced, but for some reason it was not working as intended.

My app is in: /name/appname/ and having 'name.appname' in INSTALLED_APPS was working fine in local setup.

Yet, on Heroku, I had to change the reference to just 'appname' in INSTALLED_APPS and all started working magically.

这篇关于Django自定义命令不会显示在Heroku上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆