我正在进行一些文件聚合/生成,并希望之后立即运行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。但尝试收集静态分开工作:
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错误。
所以我知道