title: Easiest method for mapping polygons in GeoDjango
body: <p>I have a simple application with a PosGIS back end. I want to have a page per feature in the database. I have used a slug and a URL routing. </p>
  
  <p>The PostGIS features have a polygon stored in a geom column which is modelled as a MultiPolygonField using geodjango. </p>
  
  <p>What is the easiest way to parse this geom column in to geojson so that I can add it to a leaflet map? </p>
  
  <p>Below is my code which is attempting to use the geojson serializer though I receive this error code on my page. </p>
  
  <p><a href="https://i.stack.imgur.com/csZ83.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/csZ83.png" alt="Error Message"></a>
  Views.py</p>
  
  <pre><code>from django.shortcuts import render
  from Countries_App.models import Countries
  from django.core.serializers import serialize
  # Create your views here.
  
  def show_country(request, country_slug):
  # Create a context dictionary which we can pass
  # to the template rendering engine.
  context_dict = {}
  try:
  # Can we find a category name slug with the given name?
  # If we can't, the .get() method raises a DoesNotExist exception.
  # So the .get() method returns one model instance or raises an exception.
          country = Countries.objects.get(slug=country_slug)
          Country_geojson = serialize('geojson', 
  Countries.objects.get(slug=country_slug))
  # We also add the category object from
  # the database to the context dictionary.
  # We'll use this in the template to verify that the category exists.
          context_dict['Countries'] = country
  except KeyError:
      country = []
      context_dict['Countries'] = Countries
      country_slug = none
      Country_geojson = serialize('geojson', 
  Country.objects.filter(name=country_slug))
  # Go render the response and return it to the client.
  return render(request, 'Countries_App/country.html', {'context_dict': 
  context_dict, 'Country_geojson': Country_geojson})
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>urlpatterns = [
  url(r'^admin/', admin.site.urls),
  # url(r'^country/(?P&lt;country_slug&gt;[\w\-]+)/$', 
  GeoJSONLayerView.as_view(model=Countries), name='data'),
  url(r'^country/(?P&lt;country_slug&gt;[\w\-]+)/$', views.show_country, 
  name='show_country'),
  ]
  </code></pre>
  
  <p>Excerpt from template where I attempt to add geojson to leaflet map</p>
  
  <pre><code>        var geojsonfeature = '{{ Countries_geojson }}'
      L.geoJSON(geojsonFeature).addTo(map);
  </code></pre>
  
  <p>Am I approaching this in the right way? What is the easiest way to simply add a PostGIS polygon geometry to a template? Bearing in mind I only want to add the geometry of the feature that matches the slug. </p>