Django:管理。未找到py自定义命令

时间:2021-01-19 23:19:24

When I do python manage.py help

当我做python管理时。py帮助

[myapp]
        update_overall_score 
        update_periodic_score

my custom command is listed, in which I can able to run update_periodic_score through python manage.py update_periodic_score but when I try the other one, I get the Unknown command: 'update_overall_score' error.

列出了我的自定义命令,其中我可以通过python管理运行update_periodic_score。py update_periodic_score但是当我尝试另一个时,我得到了未知的命令:'update_overall_score'错误。

What would be the problem? Both the files are placed in myapp/management/commands directory with __init__.py in all the directories.

问题是什么?这两个文件都放在myapp/management/commands目录中,带有__init__。所有目录中的py。

This is my update_overall_score.py,

这是我的update_overall_score.py,

from django.core.management.base import BaseCommand, CommandError
from myapp.models import Users

class Command(BaseCommand):
    """
    Updates the overall_score field of every user.
    """
    def handle(self, *args, **options):
        all_users = Users.objects.all()
        try:
            for user in all_users:
                likes = user.likes_received.count()
                stars = user.stars_received.count()
                user.overall_score = likes + stars
                user.save()
        except Exception, e:
            print e
            return
        print "Updated Overall Score."
        return

1 个解决方案

#1


2  

I had the same exact problem. After a few hours of searching through manage.py code it showed up that this was caused by my settings file configurations. I was using Mezzanine as my CMS. When you use it Mezzanine kind of says that you can put some apps under OPTIONAL_APPS variable, so I had my custom app under this variable but not in INSTALLED_APPS. Moved back to INSTALLED_APPS and everything started working as expected.

我也有同样的问题。经过几个小时的搜索之后。py代码显示这是由我的设置文件配置引起的。我使用夹层作为我的CMS。当你使用它时,Mezzanine表示你可以把一些应用放在OPTIONAL_APPS变量下,所以我有我的自定义应用在这个变量下,但不是在INSTALLED_APPS中。回到INSTALLED_APPS,一切都开始正常工作。

Make sure you have your application nowhere else than under INSTALLED_APPS. manage.py looks exactly to this constant.

确保您的应用程序除了在INSTALLED_APPS下之外没有其他地方。管理。py看起来就是这个常数。

#1


2  

I had the same exact problem. After a few hours of searching through manage.py code it showed up that this was caused by my settings file configurations. I was using Mezzanine as my CMS. When you use it Mezzanine kind of says that you can put some apps under OPTIONAL_APPS variable, so I had my custom app under this variable but not in INSTALLED_APPS. Moved back to INSTALLED_APPS and everything started working as expected.

我也有同样的问题。经过几个小时的搜索之后。py代码显示这是由我的设置文件配置引起的。我使用夹层作为我的CMS。当你使用它时,Mezzanine表示你可以把一些应用放在OPTIONAL_APPS变量下,所以我有我的自定义应用在这个变量下,但不是在INSTALLED_APPS中。回到INSTALLED_APPS,一切都开始正常工作。

Make sure you have your application nowhere else than under INSTALLED_APPS. manage.py looks exactly to this constant.

确保您的应用程序除了在INSTALLED_APPS下之外没有其他地方。管理。py看起来就是这个常数。