I have a Django-based project on GitHub that I'd like everyone to be able to deploy using the one-click deploy button. It does not use the django.contrib.staticfiles
app.
I have the following app.json
file at the root of the project:
{
"name": "Django project",
"description": "A hello world Django-based project",
"repository": "https://github.com/john-doe/django-project",
"keywords": ["python", "django"],
"scripts": {
"postdeploy": "python manage.py migrate --noinput"
},
"addons": [
"heroku-postgresql"
],
"success_url": "/",
"env": {
"SECRET_KEY": {
"description": "A randomly generated secret to secure your Django installation.",
"generator": "secret"
}
}
}
The problem is, even though I don't have 'django.contrib.staticfiles'
in the list of INSTALLED_APPS
, Heroku automatically runs python manage.py collectstatic --noinput
when someone tries to deploy my app, causing the build to fail.
How do I instruct Heroku NOT to run collectstatic
on deploy?
Go to Heroku Dashboard -> Settings
Choose Config Variables. There, enter
Key-> DISABLE_COLLECTSTATIC Value-> 1
For reference, you can see the picture below.
Just add "DISABLE_COLLECTSTATIC": { "value": "1" }
to your env
object in your app.json
, like so:
"env": {
"DISABLE_COLLECTSTATIC": {
"description": "Don't run python manage.py collectstatic --noinput on deploy",
"value": "1"
}
}
You can also do this from the terminal if you have an existing Heroku app with the following command:
heroku config:set DISABLE_COLLECTSTATIC=1
More about Django's static assets on Heroku
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