Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contrib.staticfiles and Django admin media

I just switched from 1.2 to trunk (r15175 at this writing) to play with contrib.staticfiles, and now when using the local devserver all my admin media returns a 404. The static media (as managed by the new contrib app) all work as expected, but I'd like to be able to use the admin with the dev server so that I don't have to restart a local apache instance when dev code changes.

Is this known behaviour? I haven't gotten a response in IRC.

edit: Seems related to: Admin media disappear while running django trunk in development mode, but there didn't seem to be an actual answer there.

like image 756
saturdayplace Avatar asked Jan 14 '11 18:01

saturdayplace


People also ask

What is Django contrib Staticfiles?

django. contrib. staticfiles collects static files from each of your applications (and any other places you specify) into a single location that can easily be served in production.

What is the difference between static and media in Django?

Static files are meant for javascript/images etc, but media files are for user-uploaded content.

How do I serve media files in Django?

To make Django development server serve static we have to add a URL pattern in sitewide urls.py file. Now visit http://127.0.0.1:8000/media/python.png again, this time you should be able to see the image. Just as with static files, in the production, you should always use a real web server to serve media files.


1 Answers

I was having the same problem, finally noticed this line in the docs for ADMIN_MEDIA_PREFIX:

For integration with staticfiles, this should be the same as STATIC_URL followed by 'admin/'.

Doing that fixed it for me.

Edit 2012-03-12: Note that as of Django 1.4, ADMIN_MEDIA_PREFIX has been deprecated.

like image 187
Wogan Avatar answered Oct 26 '22 14:10

Wogan