0

我正在做一些文件聚合/生成,然后想立即运行 collectstatic 。理想情况下,我要么扩展 collectstatic 命令(我不知道这是否可能),要么将控制链接到该命令。我已经尝试了第二个,它不起作用:

class Command(BaseCommand):
    can_import_settings = True

    def handle(self, *args, **options):
        something_necessary()
        execute_from_command_line('collectstatic')

非常感谢这个 django 新手。

从命令行运行的编辑很有趣

C:\www\app>python manage.py customCmd
ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'

好吧 - 这很有趣,因为我的命令不使用 MySQLdb。但是单独尝试 collectstatic 是有效的:

C:\www\app>python manage.py collectstatic
C:\Python33\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py:65: DeprecationWarning: stat_float_times() is deprecated
  os.stat_float_times(False)


You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

如果我写的命令很简单

from django.core.management.base import BaseCommand

class Command(BaseCommand):
    can_import_settings = False

    def handle(self, *args, **options):
        pass

我从命令行运行得到 MySQLdb 错误。

所以我知道

  1. 如果我没有调用 execute_from_command_line,它可以从 PyCHarm 正常工作
  2. 我无法从命令行执行我的自定义命令(python manage,py customCmd)
  3. collectstatic 从 PyCHarm 界面和命令行都可以正常工作
4

0 回答 0