How to serve static files to AWS when deploying Django app (`python manage.py collectstatic` didn't work)?

前端 未结 2 926
小蘑菇
小蘑菇 2020-12-28 20:28

Yesterday, I created this post: DjangoRestFramework browsable api looks different locally vs when deployed on server?

Basically, when I did python manage.py ru

2条回答
  •  轮回少年
    2020-12-28 20:54

    This is what worked for me.

    Remove any staticfiles directives from .config files. Find Static Files section under the Software Configuration. The left column is each of your /static/ url. The right is your static folder relative to your parent directory.

    Make sure your STATIC_ROOT setting matches the value on the right. Don't forget the trailing /.

    Pasting my settings anyway.

     STATIC_URL = '/static/'
     STATICFILES_DIRS = ('assets',)
     STATIC_ROOT = os.path.join(BASE_DIR, '..', 'www', 'static')
    

    And this is what my folder structure looks like relative to the settings files

    project/
    ├── __init__.py
    ├── settings
    │   ├── base.py
    │   ├── __init__.py
    │   ├── local.py
    │   ├── production.py
    

    wsgi.py, urls.py are located in project folder. www folder is one level above project folder.

    Hope this saves your Sunday at least.

提交回复
热议问题