Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing "Media" files in Django
    primarykey
    data
    text
    <p>I'd like to love Django, but this business of static and media files in development environments is driving me nuts. Please rescue me from my stupidity.</p> <p>I'm on my development machine. I have folder <code>media</code> in the root of my project directory.</p> <p>In <code>settings.py</code> I have: <code>MEDIA_ROOT = ''</code> and <code>MEDIA_URL = '/media/'</code>. </p> <p>In <code>urls.py</code> I have:</p> <pre><code>if settings.DEBUG: urlpatterns += patterns('', url(r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, }), ) </code></pre> <p>But the only way I can get media files is by referencing <code>/media/media/</code> e.g. <code>&lt;img src="/media/media/image.png" /&gt;</code>. </p> <p>I expect (and want)<br> <code>&lt;img src="/media/image.png" /&gt;</code></p> <p>Can anyone tell me what is happening here, and give me a simple recipe for setting up media file handling?</p> <p>Thank you very much.</p> <hr> <p>@Timmy O'Mahony - thanks! epic post, and very clear. But it leaves a couple of questions: </p> <p>(1) I have to use <code>/media/</code> and <code>/static/</code>, not <code>media/</code> and <code>static/</code> as <code>MEDIA_URL</code> and and <code>STATIC_URL</code> - am I missing something? </p> <p>(2) If <code>collectstatic</code> hoses <code>/static/</code>, where do you put site level CSS e.g. the site's CSS files? Not in <code>/static/</code>, evidently. </p> <p>(3) I put them in a directory '_' off the project root and set <code>STATICFILES_DIRS</code> to point to it - and that seems to be where the development server gets its static files, despite the <code>urlpatterns</code> directive. If THAT is wrong, where do you put site level CSS during development, and what is the workflow around <code>collectstatic</code> when you modify them - do you have to edit them one place, and collect them someplace else after every edit? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload