Location of static files when creating a Django exe using pyinstaller

前端 未结 3 1156
北荒
北荒 2021-01-14 03:26

I have a Django project with the following structure: root videos static templates

and the STATIC_URL setting in settings.py is STATIC_URL = \'/static/\'

3条回答
  •  庸人自扰
    2021-01-14 03:57

    First make sure that django.contrib.staticfiles is included in your INSTALLED_APPS in settings.py. Then have to insert in your settings.py for example this one:

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
    ]
    

    I hope definition of BASE_DIR you have in the top of settings.py. BASE_DIR points to a folder, where your manage.py file exists. So if you would have static files in the same dir, then you leave above setting as it is. If not, let's say in the same dir, next to manage.py you will have folder named app, then your settings should look like:

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "app/static"),
    ]
    

    And you can even run:

    python manage.py collectstatic
    

    To get admin static files into your static directory.

    Hope that helps.

提交回复
热议问题