Tuesday, October 15, 2013

Re: Django data to Javascript

On Tue, Oct 15, 2013 at 6:46 AM, drakko <gundars.m@gmail.com> wrote:
Hello!

I'm new to Django and Javascript and so I need some help with passing list from django template to Javascript.

The list is available in template (template.html) by using 

{% for shbf in should_have_found_list %}

but I have no idea how to access this list from Javascript.

The should_have_found_list is created in context.py file like:

should_have_found_list = ShouldHaveFound.objects.filter(enabled=1)

and passed to template in view.py as a part of dictionary:

return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'fields': simplejson.dumps(form.field_mapping),
    }))

I would appreciate some guidance :)

You can embed js anywhere in your template, e.g.:

{% for shbf in should_have_found_list %}
    <script type="text/javascript">
        my_js_function(shbf);
    </script>
{% endfor %} 

--
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+unsubscribe@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/CACwCsY4PvmRLOkpCrsRps4xLixqRbjkeMhqdvoOuS%2B3g9-RgEA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate