Sumit Sumit - 4 months ago 10
Python Question

How to instruct Heroku NOT to run collectstatic automatically on deploy?

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?

Answer

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"
  }
}

Also, if you have an existing Heroku app that you want to disable static collection from, run heroku config:set DISABLE_COLLECTSTATIC=1.