Django新手部署Heroku遇推送失败及requirements.txt缺失问题求助
Hey there! I know it's super frustrating when you follow a book step-by-step and still hit roadblocks with deployment—let's get your Django app pushed to Heroku smoothly. Let's break down and fix the two main issues from your logs:
1. Missing requirements.txt File
The error cp: cannot stat '/tmp/build_f896374c/requirements.txt': No such file or directory pops up because Heroku's Python buildpack expects a requirements.txt file (even though your logs show you're using Pipenv).
Since you're using Pipenv, generate this file easily with one command:
pipenv lock -r > requirements.txt
This exports your Pipenv dependencies into the format Heroku needs. Don't forget to add this file to Git:
git add requirements.txt
2. Unconfigured STATIC_ROOT for Static Files
The second error ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting happens because Heroku needs a defined path to collect all your static assets (CSS, JS, images) when running collectstatic.
Open your project's settings.py and add this line (using the modern path syntax from Django for Beginners):
STATIC_ROOT = BASE_DIR / 'staticfiles'
If you're on an older Django version, use this instead:
import os STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Add this change to Git as well:
git add settings.py
Final Deployment Steps
Commit all your fixes and push to Heroku again:
git commit -m "Fix Heroku deployment: add requirements.txt and STATIC_ROOT" git push heroku master
A quick heads-up: You'll see a suggestion to run heroku config:set DISABLE_COLLECTSTATIC=1 to skip static collection, but don't do this—it will break static file serving in production. Configuring STATIC_ROOT is the proper, long-term fix.
内容的提问来源于stack exchange,提问作者Junwen Huang

