I'm writing a Python app for heroku. Flask is used for the web component of the app.
My problem is that I can't find a way to serve static files. I don't want to do it through flask because that is very inefficient.
I'm also using gunicorn. How would I set up serving of static files?
Clearly, static files (defaults to index. html) can't be served directly on Heroku. So we need to transform static web app into any of these supported web apps. The simplest alternative is to use Node.
Collectstatic during builds When a Django application is deployed to Heroku, $ python manage.py collectstatic --noinput is run automatically during the build. A build will fail if the collectstatic step is not successful.
Unfortunately, the Django development server doesn't serve media files by default. Fortunately, there's a very simple workaround: You can add the media root as a static path to the ROOT_URLCONF in your project-level URLs.
Try using Amazon s3 for storing static and media files. A similar question and answer can be found here. Here is heroku's documentation of using s3. Then you might want to disable automatic collectstatic instructions here so collectstatic isn't run every time you push to heroku. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With