Opened 8 years ago

Closed 8 years ago

#6746 closed (fixed)

`GoogleMap` does not use `mark_safe`.

Reported by: bemclaugh@… Owned by: jbronn
Component: GIS Version: gis
Severity: Keywords: gis google GoogleMap
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Working with the example in contrib/gis/maps/google/

HTML does not render correctly, for example:
renders as:

Using mark_safe in the view:

from django.utils.safestring import mark_safe
from import *
from django.contrib.gis.shortcuts import *

def test(request):
    return mark_safe(render_to_response('base.html', {'google' : GoogleMap(key="blah")}))

produces a traceback:

Traceback (most recent call last):

  File "/opt/local/lib/python2.5/site-packages/django/core/servers/", line 277, in run
    self.result = application(self.environ, self.start_response)

  File "/opt/local/lib/python2.5/site-packages/django/core/servers/", line 631, in __call__
    return self.application(environ, start_response)

  File "/opt/local/lib/python2.5/site-packages/django/core/handlers/", line 209, in __call__
    response = middleware_method(request, response)

  File "/opt/local/lib/python2.5/site-packages/django/middleware/", line 90, in process_response
    if response.status_code == 404:

AttributeError: 'SafeString' object has no attribute 'status_code'

Change History (5)

comment:1 Changed 8 years ago by derelm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed


the traceback is generated by django-core because you're returning a string (SafeString) instead of a HttpResponse-object.
Just add a HttpResponse around mark_safe and you should be fine.

Closing this as invalid.

comment:2 Changed 8 years ago by jbronn

  • Keywords gis google GoogleMap added
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

While the submitter's syntax is incorrect with respect to returning a HttpResponse object, there is an underlying problem -- HTML code produced by the GoogleMaps object is not marked as safe. Thus, when used in templates it is escaped (and thus the GoogleMaps XHTML and JavaScript will not work). Confirmed as a bug, and working on a fix.

comment:3 Changed 8 years ago by jbronn

  • Owner changed from nobody to jbronn
  • Status changed from reopened to new

comment:4 Changed 8 years ago by jbronn

  • Status changed from new to assigned
  • Summary changed from mark_safe produces traceback with GoogleMap object to `GoogleMap` does not use `mark_safe`.

comment:5 Changed 8 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [7213]) gis: Fixed #6746 by marking safe GoogleMap internal XHTML/JavaScript; added support for GPolygon and GPolyline overlays via the polygons and polylines keywords; the zoom keyword may now take a geometry for automatic zoom level determination; *.pyc files are now ignored in django.contrib.gis modules.

Note: See TracTickets for help on using tickets.
Back to Top