[Answer]-Referencing a static file in a custom command

1👍

Two ways to do it…

  1. If you define STATIC_ROOT = os.path.join(PROJECT_DIR,'static') in settings.py file then you can access the static directory like

    /commands/mycommand.py
    from django.conf import settings
    pprint.pprint(settings.STATIC_ROOT)
    
  2. Or import static object

    /commands/mycommand.py
    from django.templatetags.static import static
    url = static('myapp/myfile.txt')
    

Leave a comment