Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 500
Sumit Avatar asked Dec 19 '22 16:12

Sumit


2 Answers

Go to Heroku Dashboard -> Settings

Choose Config Variables. There, enter
Key-> DISABLE_COLLECTSTATIC Value-> 1

For reference, you can see the picture below. Heroku disable collect static

like image 182
Pranjal Avatar answered Dec 21 '22 10:12

Pranjal


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

like image 31
Sumit Avatar answered Dec 21 '22 10:12

Sumit