Search code examples
djangocollectstatic

How can I call collectstatic routine inside a django app?


My Django app works with css/html themes and I can upload new themes from the user interface, that is, a regular user can upload a new theme without asking for a IT guy. I usually call a os.run('python manage.py collectstatic') but I would like to know if it is possible to do it in a more elegant or pythonic way.


Solution

  • You can use call_command(...)--(doc) as,

    from django.core import management
    
    management.call_command("collectstatic")