Changes between Version 2 and Version 3 of CookBookUsingExternalMedia


Ignore:
Timestamp:
Nov 30, 2009, 9:02:09 AM (14 years ago)
Author:
oyvind
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBookUsingExternalMedia

    v2 v3  
    88}}}
    99
    10 You would instead insert {{media_url}} so that it would look like:
     10You would instead insert {{ MEDIA_URL }} so that it would look like:
    1111
    1212{{{
    13 blah blah <img src="{{media_url}}/img/foo.jpg" alt="this is a foo"> blah blah..
     13blah blah <img src="{{ MEDIA_URL }}/img/foo.jpg" alt="this is a foo"> blah blah..
    1414}}}
    1515
    1616It generally requires a big search and replace the first time you implement it. After that, seeing other
    17 references in the templates has been enough to remind me to use {{media_url}} before any static content.
     17references in the templates has been enough to remind me to use {{ MEDIA_URL }} before any static content.
    1818
    19 We could pass {{media_url}} in through each view, but since we'll want it throughout the site, it's often easier to
     19We could pass {{ MEDIA_URL }} in through each view, but since we'll want it throughout the site, it's often easier to
    2020set up a simple context processor to do the heavy lifting.
     21
     22Note: There is a default media context processor since version 1.0. You can access using {{ MEDIA_URL }} in your templates.
     23
     24Then in the settings.py under TEMPLATE_CONTEXT_PROCESSORS, add:
     25   "django.core.context_processors.media",
     26
     27But if you are still on django 0.96:
    2128
    2229Here's a example snippet from a context process:
    2330
    2431{{{
    25 from myproject import constants
    2632from django.conf import settings
    2733
    2834def common(request):
    29     ctx = {}
    30     ctx['constants'] = constants
    31     ctx['media_url'] = settings.MEDIA_URL
    32     ... more stuff here ...
    33     return ctx
     35    return {'MEDIA_URL': settings.MEDIA_URL}
    3436}}}
    3537
    3638Then in the settings.py under TEMPLATE_CONTEXT_PROCESSORS, we added:
    37    "myproject.context_processors.common",
     39   "mysite.context_processors.common",
    3840
    39 and from there, the MEDIA_URL in settings.py became available in all templates as {{media_url}}.
    40 
    41 Note: There is a default media context processor since revision 5379 and will be included in version 0.97 once it is released.  See http://code.djangoproject.com/changeset/5379.  You can access using {{ MEDIA_URL }} in your templates.
     41and from there, the MEDIA_URL in settings.py became available in all templates as {{ MEDIA_URL }}.
Back to Top