django 1.4 : gunicorn can't find static files. settings option

1,780 views
Skip to first unread message

Bolang

unread,
May 15, 2012, 10:56:06 PM5/15/12
to django...@googlegroups.com
Hi,
I just started to using django 1.4 with gunicorn 0.14.3
With ./manage.py runserver , i can start django properly and django can
find my files in static directory.
Then i use gunicorn and then gunicorn can't find my files in static
directory.

I have tried these combination
gunicorn myproject.wsgi:application --settings myproject.settings
gunicorn myproject.wsgi:application --settings /absolute/path/to/settings.py
./manage.py run_gunicorn --settings=myproject.settings

All of the commands can start django, but can't find my files in static
directory

I also found this issue https://github.com/benoitc/gunicorn/issues/322
But, i can't find the solution from that page.

Any kind of help will be appreciated

Thanks

huseyin yilmaz

unread,
May 16, 2012, 2:08:39 AM5/16/12
to Django users
For development, you could add this to main urls.py like this.
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT, 'show_indexes':True}),

But for production use your web server to serve static files.

At least this is how I solved it. I hope that helps.

On May 16, 5:56 am, Bolang <boo.l...@gmail.com> wrote:
> Hi,
> I just started to using django 1.4 with gunicorn 0.14.3
> With ./manage.py runserver , i can start django properly and django can
> find my files in static directory.
> Then i use gunicorn and then gunicorn can't find my files in static
> directory.
>
> I have tried these combination
> gunicorn myproject.wsgi:application --settings myproject.settings
> gunicorn myproject.wsgi:application --settings /absolute/path/to/settings.py
> ./manage.py run_gunicorn --settings=myproject.settings
>
> All of the commands can start django, but can't find my files in static
> directory
>
> I also found this issuehttps://github.com/benoitc/gunicorn/issues/322

Bolang

unread,
May 16, 2012, 3:44:15 AM5/16/12
to django...@googlegroups.com
On 05/16/2012 01:08 PM, huseyin yilmaz wrote:
> For development, you could add this to main urls.py like this.
> (r'^static/(?P<path>.*)$', 'django.views.static.serve',
> {'document_root': settings.STATIC_ROOT, 'show_indexes':True}),

Thanks,
It solves the problem!

Mahdi Mazaheri

unread,
Jan 5, 2014, 4:10:02 AM1/5/14
to django...@googlegroups.com
Hi Huseyin,

I have the same problem as Bo but this again did not solve my problem. This works with django webserver (runserver) but not with gunicorn.
Any Ideas?

Thanks in advance
Mahdi

Denis Cornehl

unread,
Jan 5, 2014, 4:15:17 AM1/5/14
to django...@googlegroups.com
Hi, 

if you don’t have a web server available (for example on some PaaS like Heroku), you can do two things for production-ready static file serving: 

- use an external service like Amazon S3 (with the help of django-storages)
- use dj-static, which uses an WSGI middleware to serve your static files and integrates into django (alternative is SharedDataMiddlware of werkzeug, used by flask)

Don’t forget that you have to run „./mange.py collectstatic“ to gather all the files in one directory. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6e99aaf4-44e9-4fff-8ada-d5fc96e55d7b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



-- 
Freundliche Grüße

Denis Cornehl
Simon-Dach-Str. 7 / 10245 Berlin

M: +49 (151) 25 25 1450
@: denis....@gmail.com

X: http://xing.to/dc

Reply all
Reply to author
Forward
0 new messages