Thank you very much!
So you mean if I want pass the 'tags' list to the javascrip, the your code
example should be added in the views.py. After that, I can use the list by
using var x = {{variable_to_insert_into_template}} in my javascript?
Regards
Min
Quoting Alex Robbins :
>
> Sorry, a
Thanks
Another problem is that, when I pass the
'variable_to_insert_into_template' to the jQuery function by using var
y = {{ variable_to_insert_into_template }}.
There is a error in fileBug, which is the invalid property id [Break
on this error] var y = {{ variable_to_insert_into_template }}\n
Yeah, that code would go in the views.py. simplejson is just an easy
way to turn python variables into a string that javascript would be
able to evaluate.
Actually, if you are going to use the var x = make sure you take the
"" tags out of my example.
I think your template should look like this:
<
Thank you very much!
So you mean if I want pass the 'tags' list to the javascrip, the your
code example should be added in the views.py. After that, I can use
the list by using var x = {{variable_to_insert_into_template}} in my
javascript?
Regards
Min
On Jan 31, 3:48 am, Alex Robbins
wrote:
Sorry, a code sample would have been more helpful.
With a python variable "tags" that has a list of tags to pass to js,
it would look roughly like this:
tags = ['fun', 'exciting', 'cool']
from django.utils import simplejson
variable_to_insert_into_template = "%s" %
simplejson.dumps(tags)
Pass v
You might also consider using simplejson to dump the python variable
into something that JavaScript could understand. (This way you can
pass more complicated variables like an array or an object.) I
recently did that to get a list of tags out to some javascript on the
front end.
On Jan 29, 11:33
On Jan 30, 6:09 am, min wrote:
> Thanks a lot.
>
> Besides, what's the meaning for the 'escape_js' in [var x =
> "{{ variable|escape_js }}"] ?
>
> Regards
> Min
>
> On Jan 30, 4:33 pm, Malcolm Tredinnick
> wrote:
>
> > On Thu, 2009-01-29 at 21:11 -0800, min wrote:
> > > Hi.
>
> > > First, the
Thanks a lot.
Besides, what's the meaning for the 'escape_js' in [var x =
"{{ variable|escape_js }}"] ?
Regards
Min
On Jan 30, 4:33 pm, Malcolm Tredinnick
wrote:
> On Thu, 2009-01-29 at 21:11 -0800, min wrote:
> > Hi.
>
> > First, the code in the forms.py:
>
> > class TestForm(forms.Form):
> >
On Thu, 2009-01-29 at 21:11 -0800, min wrote:
> Hi.
>
> First, the code in the forms.py:
>
> class TestForm(forms.Form):
> name = forms.CharField( max_length=30 )
>
> Then, the variable is defined in the views.py:
>
> def Test_page(request):
> form = TestForm()
> show_results = Fal
Hi.
First, the code in the forms.py:
class TestForm(forms.Form):
name = forms.CharField( max_length=30 )
Then, the variable is defined in the views.py:
def Test_page(request):
form = TestForm()
show_results = False
variable = ''
if request.GET.has_key('name'):
show_
10 matches
Mail list logo