Opened 11 years ago

Closed 11 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: no UI/UX: no


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 11 years ago by derelm

Resolution: invalid
Status: newclosed


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 11 years ago by jbronn

Keywords: gis google GoogleMap added
Resolution: invalid
Status: closedreopened
Triage Stage: UnreviewedAccepted

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 11 years ago by jbronn

Owner: changed from nobody to jbronn
Status: reopenednew

comment:4 Changed 11 years ago by jbronn

Status: newassigned
Summary: mark_safe produces traceback with GoogleMap object`GoogleMap` does not use `mark_safe`.

comment:5 Changed 11 years ago by jbronn

Resolution: fixed
Status: assignedclosed

(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