On Tue, Aug 4, 2015 at 9:14 AM, Déborah Leder <debdeb...@gmail.com> wrote:
> Hello
>
> I am currently developping a django geolocalisation application. Therefore,
> I need both python and javascript.
> I would like to give some parameters to a script in a template, that is to
> say, in my template, I want to use the script tag to define/modify some
> javascript variables.
> Here is my code (that doesn't work) :
> <script type="text/javascript" src="{% static "js/geomap_var.js"
> %}"></script>
> {% for current_addr in mymodel.addresses.all %}
>     <script type="text/javascript">
>     my_markers.push(
>         {
>             lat: {{current_addr.lat}},
>             lon: {{current_addr.lon}},
>             description: {{current_addr.description | safe }}
>         }
>         );
>     </script>
> {% endfor %}
> <script type="text/javascript" src="{% static "js/geomap_body.js"
> %}"></script>
>
>
> When I define the array of objects my_markers in my script by giving only
> "hard-coded" numbers and strings, it works fine, so I guess that the problem
> is to recognize and evaluate the lat, lon, and description attributes of my
> address class.
>
> And I also don't know how to display the value of a javascript array in a
> template, so it makes it quite hard for debugging.
>
> If it helps, mymodel is a model that has a field : addresses =
> ManyToManyField(address)

I do things like that all the time, so you must have some other issue.
I'd run the python script in the debugger and verify that values are
indeed getting passed in your context.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY7bA%2BwXZhnLLRdMAhLt7VnTjnruxrLJf26vTUze1BMsPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to