Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collectstatic configuration error when deploying Django app with dokku

When deploying a Django app using dokku I am getting a following error

Collectstatic configuration error. To debug, run:
$ heroku run python ./manage.py collectstatic --noinput

I found no way to run heroku run python ./manage.py collectstatic --noinput for a dokku container, but when I am trying dokku run my app python ./manage.py collectstatic --noinput, the static files are successfully copied to the STATIC_ROOT folder and no error message given.

I could solve the problem by placing collectstatic command into Procfile:

web: python manage.py collectstatic --noinput ; gunicorn myapp.wsgi

Still, I would love to know what was causing the problem and how can it be debugged. Any ideas?

like image 507
silentser Avatar asked Jul 30 '14 14:07

silentser


People also ask

What is Collectstatic Noinput?

So django by default overwrites your modified files on collectstatic command, --noinput flag means it will not ask for your permission.

What is Django Heroku?

This is a Django library for Heroku applications that ensures a seamless deployment and development experience. This library provides: Settings configuration (Static files / WhiteNoise). Logging configuration. Test runner (important for Heroku CI).


1 Answers

You should have four settings in your settings.py file called MEDIA_ROOT, MEDIA_URL, STATIC_ROOT and STATIC_URL.

I set mine like so:

MEDIA_ROOT = 'media' STATIC_ROOT = 'static' MEDIA_URL = '/media' STATIC_URL = '/static'

Inside the docker container that gets created, you will find your application under /app which makes the media path /app/media/ and the static path /app/static/.

Unfortunately if you don't have a media and static folder committed in git, it won't get created under /app automatically.

Since git doesn't allow you to commit an empty folder (it only commits files), I do the following in my projects:

mkdir media static touch media/.dir touch static/.dir git add media/.dir static/.dir git commit -m 'Make media and static directories'

The 'touch' command creates an empty file, then you 'git add' the two newly-created files and check them in.

Now when you push, the directories will be there to contain the media and static files. Just keep in mind that every time you 'git push', a new container is created, and the old one is destroyed. While this isn't a problem for your static files, your media will be lost unless you store it somewhere else.

like image 149
Aaron C. de Bruyn Avatar answered Sep 30 '22 07:09

Aaron C. de Bruyn