title: Unable to display image using django
body: <p>I am new to using django. In my app, I am uploading images that is being stored to the media folder. Now, I am trying to provide the link for downloading the image which is not working. I also tried to display the image directly( using img in html) which is not working either.</p>
  
  <p>My code is as follows:</p>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  from django.conf import settings
  from django.conf.urls.static import static
  
  
  app_name = 'workers'
  
  urlpatterns = [
  url(r'^$', views.index, name= 'index'),
  url(r'^enrollment$',views.enroll, name='enroll'),
  url(r'^save_enrollment$',views.save_enrollment, name='save_enrollment'),
  
  ]
  
  if settings.DEBUG:
  urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  from django.forms import ModelForm
  from .models import Worker
  
  class Worker_enrollment(forms.ModelForm):
      name = forms.CharField(max_length=250)
      address = forms.CharField(max_length=500)
      phone_number = forms.CharField(max_length=100)
      designation = forms.CharField(max_length=1000)
      docfile = forms.FileField(label='select an image to upload')
      ssn = forms.CharField(max_length=200)
  
      class Meta:
          model = Worker
          fields = ['name','address','phone_number','designation','docfile','ssn']
  </code></pre>
  
  <p>models.py:-</p>
  
  <pre><code>from django.db import models
  
  class Worker(models.Model):
      name = models.CharField(max_length=250)
      address = models.CharField(max_length=500)
      phone_number = models.CharField(max_length=100)
      designation = models.CharField(max_length=1000)
      docfile = models.ImageField(upload_to='documents/')
      ssn = models.CharField(max_length=200)
      def __str__(self):
          return (self.name)
  </code></pre>
  
  <p>views.py:-</p>
  
  <pre><code>from .models import  Worker
  from .forms import Worker_enrollment
  from django.shortcuts import render, get_object_or_404
  from django.conf import settings
  
  def index(request):
      workers_info = Worker.objects.all()
      context = {
      'workers':workers_info
  }
  return render(request, 'workers/index.html', context)
  
  def enroll(request):
      form = Worker_enrollment(request.POST)
      if form.is_valid():
          return render(request, 'workers/enroll.html', {'form': form})
      else:
          form = Worker_enrollment()
      return render(request, 'workers/enroll.html', {'form': form})
  
  def save_enrollment(request):
      worker_info = Worker()
      if request.method == 'POST':
          form = Worker_enrollment(request.POST,request.FILES)
          if form.is_valid():
              worker_info.name = form.cleaned_data['name']
              worker_info.address = form.cleaned_data['address']
              worker_info.designation = form.cleaned_data['designation']
              worker_info.phone_number = form.cleaned_data['phone_no']
              worker_info.ssn = form.cleaned_data['ssn']
              worker_info.docfile = request.FILES['docfile']
              worker_info.save()
              return render(request,'workers/saves_worker.html',{'worker_info':worker_info})
      else:
          form = Worker_enrollment()
      return render(request, 'workers/saves_worker.html', {'worker_info': worker_info})
  </code></pre>
  
  <p>enroll.html:-</p>
  
  <pre><code>&lt;form action="save_enrollment" method="post" enctype="multipart/form-data"&gt;
  {% csrf_token %}
  {{ form.as_ul }}
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>saves_worker.html:-</p>
  
  <pre><code>&lt;h1&gt;Worker has been enrolled&lt;/h1&gt;
  &lt;br&gt;
  &lt;h2&gt;Name - {{worker_info.name}}&lt;/h2&gt;&lt;br&gt;
  &lt;h2&gt;PhoneNo - {{worker_info.phone_number}}&lt;/h2&gt;&lt;br&gt;
  &lt;h2&gt;Designtion - {{worker_info.designation}}&lt;/h2&gt;&lt;br&gt;
  &lt;h2&gt;SSN - {{worker_info.ssn}}&lt;/h2&gt;
  &lt;h2&gt;Address - {{worker_info.address}}&lt;/h2&gt;
  &lt;h2&gt;&lt;a href="{{ worker_info.docfile.url }}" &gt;worker's image&lt;/h2&gt;
  </code></pre>
  
  <p>The following are specified in the settings.py file:-</p>
  
  <pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
  MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
  MEDIA_URL = '/media/'
  STATIC_URL = '/static/'
  STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
  </code></pre>