Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread mili9528
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

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread min
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

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread Alex Robbins
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: <

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread min
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:

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread Alex Robbins
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

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread Alex Robbins
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 

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread Almost George
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

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread min
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): > >

Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-29 Thread Malcolm Tredinnick
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

How to pass the variable which is defined in the views.py to the jQuery function

2009-01-29 Thread min
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_