Call with render_to_string not working

Issue #7 invalid
Anonymous created an issue


I tried to render a map on my front-end using a dajax call to replace the innerhtml of a div for a render_to_string of a template that only has: {% load easy_maps_tags cache%} {% easy_map "Portugal, √Čvora" 200 200 5 using 'map.html' %}

If i try on a "normal" loading view, the map loads just fine, but with the ajax call it seems to render the initialize scripts as text.

Any way of doing this?

Comments (5)

  1. Mikhail Korobov repo owner


    There are 2 issues:

    1. scripts inside <script> tags loaded via ajax may not be executed on certain conditions;
    2. google maps script does not support ajax loading (see );

    I don't know if (1) conditions are met in your case. For example, if this HTML would be loaded with Request.HTML from mootools ( then 'evalScripts' option should be set to True. JQuery's 'load' ( is also capable of executing scripts embedded in requested html. There should be a similar option in dajax underlying js library.

    As for (2), take a look at . I think the best way is to customize the map template like this:

    {# my_map.html #}
    {% extends "easy_maps/map.html" %}
    {% block api_js %}{% endblock %}

    and add

    <!-- Google Maps API javascript -->
    <script type="text/javascript" src=""></script>

    to your main (non-ajax) template.

    There is also

    {% block map_loading_js %}
    // initialize the map after page loading
    google.maps.event.addDomListener(window, 'load', initialize_map_{{ }});
    {% endblock %}

    block in default template; you'll probably have to override it as well.

    I'm leaving this ticket open because there is a room for docs improvements regarding this case.

  2. Anonymous

    Thanks for the quick response :)

    I tried some simple approaches but indeed the scripts aren't being executed from the string and i couldn't find a way in the dajax and daxice documentation, i'm asking for some feedback on the Dajax google group.

    I'll update when i find a solution

  3. liad

    Hi, My map renders but won't change if i put in different details until i runserver again (locally), is there some caching on the maps?

  4. Mikhail Korobov repo owner

    Hi liad, I don't quite understand the question - can you please provide more details:

    • how do you render the map? Does it rendering relates to this issue?
    • what do you mean by 'put in different details'?

    There is django template caching that can cause such behavior (it is not specific to django-easy-maps) - are you using 'django.template.loaders.cached.Loader' ?.

  5. Log in to comment