Re: static files, runserver debug=True

63 views
Skip to first unread message

Javier Guerra Giraldez

unread,
Jan 16, 2013, 2:19:01 PM1/16/13
to django...@googlegroups.com
On Wed, Jan 16, 2013 at 6:54 AM, Fred Kingham <fredk...@gmail.com> wrote:
> Can you serve static files like you would in production from the django
> runserver?

it depends on what you mean by "like you would in production":

if you mean "separate processes for static files and web app" then no,
it can't since it's a single server.

if you mean simply serve static files by whatever mechanisms but
keeping the same URLs, then yes. check
https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#django.contrib.staticfiles.templatetags.staticfiles.django.contrib.staticfiles.views.serve
(almost at the end of the contrib/staticfiles doc page). in short,
it simply adds some a view function to handle STATIC_URL from the
files in any directory searchable by collectstatic. note that that
means you don't have to run collectstatic for it to work, it's only
needed for deployment.


--
Javier

Fred Kingham

unread,
Jan 16, 2013, 6:31:57 PM1/16/13
to django...@googlegroups.com
perfect thanks Javier.

I guess my question should have been phrased, if debug = False, does the runserver serve static files  from the STATIC_ROOT. Clearly that's no.

Thanks again.

 Fred

Tom Evans

unread,
Jan 17, 2013, 4:40:11 AM1/17/13
to django...@googlegroups.com
On Wed, Jan 16, 2013 at 11:31 PM, Fred Kingham <fredk...@gmail.com> wrote:
> perfect thanks Javier.
>
> I guess my question should have been phrased, if debug = False, does the
> runserver serve static files from the STATIC_ROOT. Clearly that's no.
>
> Thanks again.
>
> Fred

Even with debug=True, runserver does not serve files from STATIC_ROOT,
it dynamically locates them inside your python packages on each
request. This is more expensive, but means you do not need to
constantly keep running collectstatic during development.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages