title: Django Template tag, generating template block tag
body: <p>Currently a bit stuck, wondering if anyone can assist. I am using <a href="http://github.com/carljm/django-adminfiles" rel="nofollow noreferrer">django-adminfiles</a>. Which is a neat little application. I want to use it to insert images into posts/articles/pages for a site i am building. </p>
  
  <p>How django-adminfiles works is it inserts a placeholder i.e &lt;&lt;&lt; ImageFile >>> and this gets rendered using a django template.  It also has the feature of inserting custom options i.e (Insert Medium Image) , i figured i would used this to automatically resize images and include it in the post (similar to how WP does it). </p>
  
  <p>Django-adminfiles makes use of <a href="http://thumbnail.sorl.net/docs/" rel="nofollow noreferrer">sorl.thumbnail</a> app to generate thumbnails. </p>
  
  <p>So i have tried testing generating thumbnails:</p>
  
  <p>The current template that is used to render the inserted image is:</p>
  
  <pre><code>{% spaceless %}
  &lt;img src="{{ upload.upload.url }}" width="{{ upload.width }}" height="{{ upload.height }}" class="{{ options.class }}" class="{{ options.size }}" alt="{% if options.alt %}{{ options.alt }}{% else %}{{ upload.title }}{% endif %}" /&gt;
  {% endspaceless %}
  </code></pre>
  
  <p>I tried modifying this to:</p>
  
  <pre><code>{% load thumbnail %}
  {% spaceless %}
  &lt;img src="{% thumbnail upload.upload.url 200x50 %}" width="{{ upload.width }}" height="{{ upload.height }}" class="{{ options.class }}" class="{{ options.size }}" alt="{% if options.alt %}{{ options.alt }}{% else %}{{ upload.title }}{% endif %}" /&gt;
  {% endspaceless %}
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Exception Value:    
  Caught an exception while rendering: Source file: '/media/uploads/DSC_0014.jpg' does not exist.
  </code></pre>
  
  <p>I figured the thumbnail needs the absolute path so tried putting that in the template, and that works.</p>
  
  <p>i.e this works:</p>
  
  <pre><code>{% thumbnail '/Users/me/media/uploads/DSC_0014.jpg' 200x50 %}
  </code></pre>
  
  <p>So basically i need to generate the absolute path to the file give the relative path (to web root). You could do this by passing the MEDIA_ROOT setting to the template, but the reason i want to do a template tag is to programmatically set the image size.  </p>
  
  <p><strong>Update</strong>
  Tried this as per answer below:</p>
  
  <p>templatetag:</p>
  
  <pre><code>from django import template
  from proj.settings import MEDIA_ROOT
  
  register = template.Library()
  
  @register.filter(name='path')
  def path(value):
      value = MEDIA_ROOT + '/' + value 
      return value
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>{% load thumbnail %}
  {% load images %}
  {% spaceless %}
  &lt;img src="{{ upload.upload.url|path }}" width="{{ upload.width }}" height="{{ upload.height }}" class="{{ options.class }}" class="{{ options.size }}" alt="{% if options.alt %}{{ options.alt }}{% else %}{{ upload.title }}{% endif %}" /&gt;
  {% endspaceless %}
  </code></pre>