简体   繁体   中英

Deploy a django project on Heroku (Windows) :

I'm trying to deploy a Django app from the first time using Heroku. But my app is always returning an application error.

When I check heroku logs --tail I get:

FileNotFoundError: [Errno 2] No such file or directory: '/app/CandiBot/logs/08/16.log'

The tree structure of my project looks like this, I think I missed a folder called myproject/ but I guess the issue is not related to that.

CandiEnv/ (venv)
├── Candiapp/ (app)
│   ├── models.py
│   ├── urls.py
│   ├── views.py
│   ├── ...
│   ├── static/
│   │    └──(empty)
│   └── logs/
│        └── 08/16.log  <-- Here is the log file
├── myproject/ (I don't know why I've named it differently)
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├──...
├── manage.py
└── Procfile

Maybe it has to do with my settings.py . The static part looks like this:

STATIC_URL = '/static/'
BASE_DIR= os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = ( #Not sure it's useful
    os.path.join(BASE_DIR, 'static'),
    )

What am I missing here?

This has nothing to do with your static files.

It looks like you're trying to log to a file. That won't work on Heroku due to its ephemeral filesystem : your logs will be lost whenever your dyno restarts. This happens frequently (at least once per day).

Instead, simply write to stdout or stderr . Heroku's logger will collect that output and merge it with logs from other sources. On Django that means setting up a StreamHandler instead of a FileHandler .

Note that Heroku doesn't keep logs very long . Given that you were trying to write to a file named after the current date I suspect that you might want to hang onto more than the most recent 1,500 messages / last seven days of messages. In that case, a logging addon is the simplest solution and a log drain is the most powerful.

Git does not handle empty folder well.

Try deleting the empty folder at CandiEnv/Candispo/static/ and 08/16.log . Even though this has a file extension I am guessing it is a folder with a . in the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM