Wednesday, August 1, 2018

Deploying django app to heroku - can't find file

Leave a Comment

I have a problem running my django app on heroku. It has been deployed successfully but it has some problems finding various files.

in news.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) url_path = BASE_DIR + '/marketdata/news/' 

which works locally but when I deploy it on heroku it says it can't find the file

Exception Value: [Errno 2] No such file or directory: '/app/artemis/static/marketdata/news/bloomberg_news.csv' Exception Location: /app/artemis/static/marketdata/news.py in save_to_csv, line 16

and this is my project structure

enter image description here

Any idea how this would be solved? Any tip would be greatly appreciated!

EDIT: if i check my project structure on heroku the news folder is not there at all. Does this have to do with the fact that it only has .csv files in it?

2 Answers

Answers 1

I found the solution to the issue I was having:

  • I didn't run python manage.py collectstatic before committing to heroku
  • The other problem was with my procfile. Changing it to: web: gunicorn myproject.wsgi solved my issue

Answers 2

If you haven't already done this, give this a read and follow the steps https://devcenter.heroku.com/articles/deploying-python

You probably have, but posting for reference just in case. So, those files are located within your static area. Heroku is a little interesting when it comes to static files. Another question I answered is most likely related to your issue https://stackoverflow.com/a/51373830/4954874.

The problem you are having is it can't find the file, because it is located in your static directory which in turn is found by using /static/ which allows heroku to find it. I believe if you do something like this /static/marketdata/news/ it should work.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment