On Tue, Oct 15, 2013 at 6:46 AM, drakko <[email protected]> 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 [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to