You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Django应用至Heroku时遭遇H10崩溃错误的排查求助

Fixing Django H10 Crash on Heroku (App Crashed Error)

Hey there, let's break down how to fix that H10 crash you're seeing. Based on your directory structure and Procfile setup, the most likely culprit is an incorrect path to your WSGI module—let's tackle that first, then cover other common fixes.

1. Correct Your Procfile WSGI Path

Looking at your directory structure:

ROOT/
├─ .git/
├─ Procfile
├─ api_project/
│ ├─ api_project/  # Contains wsgi.py
│ ├─ manage.py

Your current Procfile uses web: gunicorn api_project.wsgi, but from the ROOT directory (where Heroku runs commands), gunicorn can't find that WSGI module directly. Here are two working fixes:

Option A: Use --chdir to Point to the Django Project Root

Update your Procfile to first change directory to where manage.py lives, then reference the WSGI module:

web: gunicorn --chdir api_project api_project.wsgi

This tells gunicorn to switch into the api_project/ folder (with manage.py) first, then look for the inner api_project/wsgi.py module.

Option B: Use the Full Module Path from ROOT

If you don't want to use --chdir, you can reference the WSGI module using its full path from the ROOT directory. Since the inner api_project is a subfolder of the outer api_project, the module path becomes:

web: gunicorn api_project.api_project.wsgi

Just make sure the outer api_project folder has an empty __init__.py file (Django usually adds this automatically, but double-check—if it's missing, create it).

2. Verify Other Common H10 Crash Causes

Even with a fixed Procfile, these issues can still trigger an H10 error:

  • Missing Dependencies: Ensure your requirements.txt includes gunicorn and all other packages your Django app needs. Run pip freeze > requirements.txt locally to update it, then commit and push to Heroku.
  • Incorrect Django Settings:
    • Set DEBUG = False (required for production on Heroku).
    • Add .herokuapp.com to ALLOWED_HOSTS in settings.py, like:
      ALLOWED_HOSTS = ['your-app-name.herokuapp.com', 'localhost']
      
  • Unapplied Migrations: Run heroku run python manage.py migrate to apply database migrations—missing migrations can cause the app to crash on startup.
  • Check for Hidden Errors: Sometimes the H10 log doesn't show full details. Run heroku run python manage.py check to scan for Django configuration issues, or heroku run bash to access the app's shell and debug directly (try running gunicorn manually to see exact error messages).

3. Confirm Procfile Placement

You already fixed the H14 error by moving Procfile to the ROOT (with .git), which is correct—Heroku requires the Procfile to be in the root of your Git repository, so keep it there.

Once you make these changes, commit your updates and push to Heroku with git push heroku main, then check if the app starts up. If you still see errors, run heroku logs --tail again—you should now get more detailed error messages to debug further.

内容的提问来源于stack exchange,提问作者jokonoo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 21:17:39