How to solve Access to fetch at 'https://api.amadeus.com/v1/flight-offers' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access contro

2024-04-21 Thread Эля Min
I have this one:from django.middleware.common import MiddlewareMixin
from django.http import JsonResponse

class CorsMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.method == "OPTIONS" and 
"HTTP_ACCESS_CONTROL_REQUEST_METHOD" in request.META:
response = JsonResponse({"detail": "CORS policy allows this 
request"})
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET, POST, PUT, 
DELETE, OPTIONS"
response["Access-Control-Allow-Headers"] = "Content-Type, 
Authorization"
return response
return None

def process_response(self, request, response):
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, 
OPTIONS"
response["Access-Control-Allow-Headers"] = "Content-Type, 
Authorization"
return response 
AND:
CORS_ALLOWED_ORIGINS = [
'http://127.0.0.1:8000', ]
BEFORE I DID PROXY,but my project stopped before starting. Please give me 
HElp

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b81f71d-f925-437a-9e39-4c1566b05709n%40googlegroups.com.


Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
\(^o^)/

On Tue, Jul 3, 2012 at 4:53 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  You are welcome. Glad you got it working :)
>
> _Nik
>
>
> On 7/3/2012 3:33 PM, Min Hong Tan wrote:
>
> Thx nik,
>
>  I'm confused , your words has aroused me  from the word.
> "You won't use HttpResponse at all, just EmailMessage (using
> message.attach). "
>
>  problem solved by using below:
>
>
>
>  from io import BytesIO
>
>
>
>  buffer = BytesIO()
> book.save(buffer)
> excel = buffer.getvalue()
> buffer.close()
>
>  and just
>
>
> mail.attach(filename="testing.xls",content=excel,mimetype="application/ms-excel")
>
>  mail.send()
>
>  and mission accomplished!!
>
>
>
>
> On Tue, Jul 3, 2012 at 2:59 PM, Nikolas Stevenson-Molnar <
> nik.mol...@consbio.org> wrote:
>
>>  You'll need to use EmailMessage:
>> https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs/#django.core.mail.EmailMessage
>>
>> You won't use HttpResponse at all, just EmailMessage (using
>> message.attach).
>>
>> _Nik
>>
>>
>> On 7/3/2012 1:34 PM, Min Hong Tan wrote:
>>
>> sorry all, maybe i'm not type why i need the httpresponse to be attach.
>>
>>  response = HttpResponse(mimetype='application/pdf')
>> response['Content-Disposition'] = 'attaachment; filename=report.pdf'
>>
>>  i'm generating the pdf file in response. and normally i will return
>> response and it should be perfect with the pdf file download.
>>
>>  but, how if i want to attach it and send out the mail?
>>
>> On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
>> nik.mol...@consbio.org> wrote:
>>
>>> Oh, and HttpResponse is intended to send data back to a web browser. I
>>> can't think of any reason you would use an HttpResponse when sending an
>>> email.
>>>
>>> _Nik
>>>
>>> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
>>>  > hi,
>>> >
>>> > I have a problem to send mail using Emailmessage,
>>> > i wan to attach the file that render using httpresponse and send, but
>>> > always show me "int" does not have method "lower".
>>> > therefore, I think to save the file in the server and then attach
>>> > using emailmessage.  but how do i get the httpresonse to save
>>> > in server /tmp/file  ?
>>> >
>>> > Regards,
>>> > MH
>>>   > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups "Django users" group.
>>> > To post to this group, send email to django-users@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > django-users+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>>--
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
Thx nik,

I'm confused , your words has aroused me  from the word.
"You won't use HttpResponse at all, just EmailMessage (using
message.attach). "

problem solved by using below:



from io import BytesIO



buffer = BytesIO()
book.save(buffer)
excel = buffer.getvalue()
buffer.close()

and just

mail.attach(filename="testing.xls",content=excel,mimetype="application/ms-excel")

mail.send()

and mission accomplished!!




On Tue, Jul 3, 2012 at 2:59 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  You'll need to use EmailMessage:
> https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs/#django.core.mail.EmailMessage
>
> You won't use HttpResponse at all, just EmailMessage (using
> message.attach).
>
> _Nik
>
>
> On 7/3/2012 1:34 PM, Min Hong Tan wrote:
>
> sorry all, maybe i'm not type why i need the httpresponse to be attach.
>
>  response = HttpResponse(mimetype='application/pdf')
> response['Content-Disposition'] = 'attaachment; filename=report.pdf'
>
>  i'm generating the pdf file in response. and normally i will return
> response and it should be perfect with the pdf file download.
>
>  but, how if i want to attach it and send out the mail?
>
> On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
> nik.mol...@consbio.org> wrote:
>
>> Oh, and HttpResponse is intended to send data back to a web browser. I
>> can't think of any reason you would use an HttpResponse when sending an
>> email.
>>
>> _Nik
>>
>> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
>>  > hi,
>> >
>> > I have a problem to send mail using Emailmessage,
>> > i wan to attach the file that render using httpresponse and send, but
>> > always show me "int" does not have method "lower".
>> > therefore, I think to save the file in the server and then attach
>> > using emailmessage.  but how do i get the httpresonse to save
>> > in server /tmp/file  ?
>> >
>> > Regards,
>> > MH
>>   > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
sorry all, maybe i'm not type why i need the httpresponse to be attach.

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attaachment; filename=report.pdf'

i'm generating the pdf file in response. and normally i will return
response and it should be perfect with the pdf file download.

but, how if i want to attach it and send out the mail?

On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

> Oh, and HttpResponse is intended to send data back to a web browser. I
> can't think of any reason you would use an HttpResponse when sending an
> email.
>
> _Nik
>
> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
> > hi,
> >
> > I have a problem to send mail using Emailmessage,
> > i wan to attach the file that render using httpresponse and send, but
> > always show me "int" does not have method "lower".
> > therefore, I think to save the file in the server and then attach
> > using emailmessage.  but how do i get the httpresonse to save
> > in server /tmp/file  ?
> >
> > Regards,
> > MH
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
hi,

I have a problem to send mail using Emailmessage,
i wan to attach the file that render using httpresponse and send, but
always show me "int" does not have method "lower".
therefore, I think to save the file in the server and then attach using
emailmessage.  but how do i get the httpresonse to save
in server /tmp/file  ?

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Advices on what web programming language used in template?

2012-07-03 Thread Yu Min

于 2012年07月03日 19:09, kenneth gonsalves 写道:

could you clarify your question please? Do you want to know what
programming language is to be used in templates? Or do you want to know
what programming language is to be used to program templates?


Sorry for not make myself clear.
What I am wondering is, what programming language could be used in 
program the template. I know jsp probably is a good choice, but what 
other choices are there?

Thanks for hitting me up.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Advices on what web programming language used in template?

2012-07-03 Thread Yu Min

hi, guys
   I'm going through django structure. And while struggling to 
understand the django usage, I start to wonder what web programing 
language goes well with the template system.

   Will you guys kindly enough to give me some advice on this please!

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



mssql

2012-06-07 Thread Min Hong Tan
hi all,

i'm going to use django-mssql.  is there any one has use this b4? and any
working example?
am i need to define a model in models.py?? how if i run syndb. will it sync
to my default. mysql
database?

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



list indices must be integers, not str

2012-06-01 Thread Min Hong Tan
Hi all,

My error msg when i trying to pass character instead of decimal value
through the
URL pattern

URL Link:
/project1/program1_add/DUM014749/


URLS.py

url(r'^program1_add/(?P\w{1,13})/$',
'view.program_common_add''),

Is there any way to pass character instead of value?

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: output string for template render object

2012-05-27 Thread Min Hong Tan
hi Chew,

Thanks.  I have found out the html code that i render is invalid. :P  too
tire for late night programming

Regards,
MH

On Sun, May 27, 2012 at 11:17 AM, Chew Kok Hoor <kokh...@gmail.com> wrote:

> Hi Min Hong,
>
> I think you need to provide a simple example, of values in the context
> (programs, generate_html,generate_script), your template and the result as
> well as the expected result so that it is easier for forum members to help
> you.
>
> Thanks.
>
> Regards,
> Kok Hoor
>
> On Sun, May 27, 2012 at 4:28 PM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi all,
>>
>> i have one question
>> return render_to_response(mainPageTemplate,
>>   {'programs':find_program ,
>>'generate_html':generate_html,
>>'generate_script':generate_script
>>},
>>   context_instance=RequestContext(request))
>>
>> on the above return value.  i have two parameter one is return string
>> value with javascript and html components.
>> i have put the {% autoescape off %} as well to avoid conversation.  but,
>> i noticed it seems like can not capture the
>> html 's component that i specified in  the generate_html.  even
>> javascript put at $(document).ready(function(){ }
>> is it i left out anything? thanks
>>
>>
>> Regards,
>> MH
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



output string for template render object

2012-05-27 Thread Min Hong Tan
hi all,

i have one question
return render_to_response(mainPageTemplate,
  {'programs':find_program ,
   'generate_html':generate_html,
   'generate_script':generate_script
   },
  context_instance=RequestContext(request))

on the above return value.  i have two parameter one is return string value
with javascript and html components.
i have put the {% autoescape off %} as well to avoid conversation.  but, i
noticed it seems like can not capture the
html 's component that i specified in  the generate_html.  even javascript
put at $(document).ready(function(){ }
is it i left out anything? thanks


Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django connect alternate database.

2012-05-25 Thread Min Hong Tan
hi,

I have a situation.  currently i have one default django 's database.
but, i wound like to connect to mssql/other database.
- how can i get connected to ms-sql/other database?
- is it we have to create class in models? the database is for read only.
Hope able to get the information.

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



model form_set can not delete

2012-05-23 Thread Min Hong Tan
Hi there,

i have a problem whereby, if i for form in formset line by line and run
form.save().  my delete (ticked) item will not be deleted.
and if i 'm direct using formset.save(). it did deleted. where am i code
wrong already?


q1 = modelformset_factory(CustomerDetail,
   form=
CustomerDetail lForm,
   can_delete=True)
# bla bla bla

if request.method == 'POST':

find_formsetcustomerdetail =
CustomerDetail .objects.filter(customerheader__id=id_unquekey)
formset =
q1(request.POST,request.FILES,queryset=find_formsetcustomerdetail)
if formset.is_valid():
for formline in formset:
 # do checking..bla bla bla
   formline.save()

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: user.set_password('new password')

2012-05-19 Thread Min Hong Tan
thanks all :)

On Sat, May 19, 2012 at 9:49 AM, Timothy Makobu <makobu.mwambir...@gmail.com
> wrote:

> user.save returns the function object, which is a valid statement, so
> Python wont raise an Exception.
>
>
> On Sat, May 19, 2012 at 9:23 AM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi..
>>
>> thanks!! haha... didn't notice  that. how can no error...prompt out
>> one
>>
>>
>> On Fri, May 18, 2012 at 11:48 PM, Jonathan D. Baker <
>> jonathandavidba...@gmail.com> wrote:
>>
>>> Save is a method, so it needs parentheses: user.save()
>>>
>>> Sent from my iPhone
>>>
>>> On May 18, 2012, at 10:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I 'm trying to change password in views.py in one of my  def.
>>> having the below code.
>>> newpassword ="testing123"
>>> user = User.objects.get(username__exact = request.user)
>>> user.set_password(newpassword)
>>> user.save
>>>
>>> it didn't prompt me any error.  but, why my password still remained
>>> unchanged?
>>>
>>> Regards,
>>> MH
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: user.set_password('new password')

2012-05-19 Thread Min Hong Tan
hi..

thanks!! haha... didn't notice  that. how can no error...prompt out one

On Fri, May 18, 2012 at 11:48 PM, Jonathan D. Baker <
jonathandavidba...@gmail.com> wrote:

> Save is a method, so it needs parentheses: user.save()
>
> Sent from my iPhone
>
> On May 18, 2012, at 10:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>
> Hi,
>
> I 'm trying to change password in views.py in one of my  def.
> having the below code.
> newpassword ="testing123"
> user = User.objects.get(username__exact = request.user)
> user.set_password(newpassword)
> user.save
>
> it didn't prompt me any error.  but, why my password still remained
> unchanged?
>
> Regards,
> MH
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



user.set_password('new password')

2012-05-18 Thread Min Hong Tan
Hi,

I 'm trying to change password in views.py in one of my  def.
having the below code.
newpassword ="testing123"
user = User.objects.get(username__exact = request.user)
user.set_password(newpassword)
user.save

it didn't prompt me any error.  but, why my password still remained
unchanged?

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't locate 'media' directory

2012-05-17 Thread Min Hong Tan
hi,

you may try this way.
in your settings.py

import os
ROOT_PATH  =  'c:/project/ajax_tut'   # take note. need to use black slash.


On Thu, May 17, 2012 at 12:31 AM, Venkat Rangan <venkat.ran...@gmail.com>wrote:

> No, this did not work. Is there a way to print what the ROOT_PATH is, on
> an HTML page?
>
>
> On Wed, May 16, 2012 at 3:55 PM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi,
>>
>> your media folder location should be
>>
>> /media
>>
>> example: your  ROOT_PATH  is c:\project\ajax_tut
>> then your media file should be
>>
>> c:\project\ajax_tut\media
>>
>> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
>> MEDIA_URL = '/media/ <http://127.0.0.1:8000/media/>' < like this
>> should be ok.
>>
>> you may try. hope it helps.
>>
>> Regards,
>> MH
>>
>>
>> On Tue, May 15, 2012 at 8:41 PM, django-user59 
>> <venkat.ran...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I attempted to add 'media' directory to the root of my project and
>>> placed a css file and some ajax javascript. The server runtime is unable to
>>> locate it. Can someone help?
>>>
>>> I have the following in settings.py
>>>
>>> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
>>> MEDIA_URL = 'http://127.0.0.1:8000/media/'
>>>
>>> The console error I get is:
>>>
>>> C:\dev\Projects\ajax_tut\ajax_tut>python ../manage.py runserver
>>> Validating models...
>>> 0 errors found
>>> Django version 1.4, using settings 'ajax_tut.settings'
>>> Development server is running at http://127.0.0.1:8000/
>>> Quit the server with CTRL-BREAK.
>>> [15/May/2012 19:11:12] "GET / HTTP/1.1" 200 613
>>> [15/May/2012 19:11:12] "GET /media/style.css HTTP/1.1" 404 2312
>>> [15/May/2012 19:11:12] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>>> [15/May/2012 19:11:28] "GET / HTTP/1.1" 200 613
>>> [15/May/2012 19:11:28] "GET /media/style.css HTTP/1.1" 404 2312
>>> [15/May/2012 19:11:28] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>>>
>>> Where do I place this directory and what do I set in settings.py and
>>> which directory do I launch the server? Once again, any help would be much
>>> appreciated.
>>>
>>> Thanks,
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/django-users/-/XyZWqGOd6KoJ.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't locate 'media' directory

2012-05-16 Thread Min Hong Tan
hi,

your media folder location should be

/media

example: your  ROOT_PATH  is c:\project\ajax_tut
then your media file should be

c:\project\ajax_tut\media

MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
MEDIA_URL = '/media/ ' < like this
should be ok.

you may try. hope it helps.

Regards,
MH

On Tue, May 15, 2012 at 8:41 PM, django-user59 wrote:

> Hi,
>
> I attempted to add 'media' directory to the root of my project and placed
> a css file and some ajax javascript. The server runtime is unable to locate
> it. Can someone help?
>
> I have the following in settings.py
>
> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
> MEDIA_URL = 'http://127.0.0.1:8000/media/'
>
> The console error I get is:
>
> C:\dev\Projects\ajax_tut\ajax_tut>python ../manage.py runserver
> Validating models...
> 0 errors found
> Django version 1.4, using settings 'ajax_tut.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> [15/May/2012 19:11:12] "GET / HTTP/1.1" 200 613
> [15/May/2012 19:11:12] "GET /media/style.css HTTP/1.1" 404 2312
> [15/May/2012 19:11:12] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
> [15/May/2012 19:11:28] "GET / HTTP/1.1" 200 613
> [15/May/2012 19:11:28] "GET /media/style.css HTTP/1.1" 404 2312
> [15/May/2012 19:11:28] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>
> Where do I place this directory and what do I set in settings.py and which
> directory do I launch the server? Once again, any help would be much
> appreciated.
>
> Thanks,
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/XyZWqGOd6KoJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Disable ModelChoiceField field in ModelForm

2012-05-12 Thread Min Hong Tan
problem solved.

from django.forms import ModelForm,Select
prg_type =
forms.ModelChoiceField(queryset=ProgramType.objects.all(),widget=Select(attrs={'disabled':'disabled'}))


in forms.py

On Sat, May 12, 2012 at 4:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi,
>
> I have a foreign field show in the modelform, and i wish to disable it,
> may i know how to disable it in modelform?
> i tried attrs={'disabled':'disabled} but, it prompt doesn't have attrs
> attribute.
>
> Regards,
> MH
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Disable ModelChoiceField field in ModelForm

2012-05-12 Thread Min Hong Tan
hi,

I have a foreign field show in the modelform, and i wish to disable it, may
i know how to disable it in modelform?
i tried attrs={'disabled':'disabled} but, it prompt doesn't have attrs
attribute.

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: disabled or readonly field 's problem

2012-05-12 Thread Min Hong Tan
hi, thanks.

 def clean_pt_type(self):
data = self.initial['pt_type']

and solve the problem.

On Fri, May 11, 2012 at 10:56 PM, azizmb.in <m...@azizmb.in> wrote:

> Hey!
>
> You could clean the protected fields from the model data by overriding
> "clean" methods of the form. The documentation is 
> here<https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute>
> .
>
> On Sat, May 12, 2012 at 8:56 AM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi,
>>
>> i have a problem on the formmodel.  basically, to set the field read only
>> and disabled is easy.
>> but, the problem which I facing now, is a bit complicated.
>> - if set field "read-only" field. We can actually modify the record by
>> using web developer tools by press "F12"
>>   to modify the record and saved.  it did update the value for read-only
>> field.  this will be a security issue, if
>> some one know this.
>>
>> - if set field to "disabled" it will not post the key field.  but,
>> instead , it let it blank. and error shown, this field
>> is required. is ok, we can set required=false. but, it will be sending
>> key field value as blank to the database.
>>
>> How to I avoid this issue for record "Editing" without user  can modify
>> the value using F12 and show as read-only?
>>
>> Regards,
>> MH
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> - Aziz M. Bookwala
>
> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala>
>  | Github <http://github.com/azizmb>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



disabled or readonly field 's problem

2012-05-11 Thread Min Hong Tan
hi,

i have a problem on the formmodel.  basically, to set the field read only
and disabled is easy.
but, the problem which I facing now, is a bit complicated.
- if set field "read-only" field. We can actually modify the record by
using web developer tools by press "F12"
  to modify the record and saved.  it did update the value for read-only
field.  this will be a security issue, if
some one know this.

- if set field to "disabled" it will not post the key field.  but, instead
, it let it blank. and error shown, this field
is required. is ok, we can set required=false. but, it will be sending key
field value as blank to the database.

How to I avoid this issue for record "Editing" without user  can modify the
value using F12 and show as read-only?

Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



unique key error doesn't show using copy record in modelform.

2012-05-10 Thread Min Hong Tan
hi,

my scenario as below:
- I want to copy existing record and show at the form. then clear the pk
and id then it will be able to "add" instead of "update".
- all working fine. but, if the record is exist (Unique error).  it should
prompt unique key 's error.  but, in the form.is_valid
   has no trigger the error. untill the cmodel.save() only it throw
exception.  but, the form doesn't render the error message.

if without using "form = ProgramTypeForm(request.POST or
None,instance=dataObject)"  and use "form = ProgramTypeForm(request.POST or
None)",
then, it will be false if we run form.is_valid() else, it will True if we
execute form.is_valid() , or maybe my method are incorrect?

below are the coding:

__
models.py
__

class ProgramType(Standard):
pt_type = models.CharField('Program Type',
max_length=20,blank=False,unique=True)
pt_desc = models.CharField('Program Description',max_length=100)

def __unicode__(self):
return self.pt_type

class Meta:
unique_together = (('pt_type'),)

__
views.py

def form_copy(request,id_key):
dataObject = get_object_or_404(ProgramType,pk=id_key)
dataObject.pk = None
dataObject.id = None
form = ProgramTypeForm(request.POST or None,instance=dataObject)
if form.is_valid():
try:
cmodel = form.save(commit=False)
cmodel.id = None
cmodel.pk = None
cmodel.save()# < *here is the error*
 except:
  # do exception
 finally:
  # do finally
 else:
 # return form invalid render.
__
forms.py

class ProgramTypeForm(ModelForm):
pt_desc = forms.CharField(widget=forms.Textarea(attrs = {'class':
"page-text", 'cols': 30, 'rows': 10}), label='Description')
class Meta(CommonForm.Meta):
model = ProgramType


Regards,
MH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
i think i use .bind() instead of .live.  because .live will add the event
everytimes it .html again.
Thanks

On Sat, May 5, 2012 at 2:22 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> seems like .html has another problem.  it will duplicate itself (even not
> seen in the screen).
> but it did post Number of times when i submit the form.  still need to
> struggling..bugs still
> exist..
>
>
> On Sat, May 5, 2012 at 2:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>
>> hi Oscar,
>>
>> I think maybe it over some ajaxsetup({cache:false}) prevention when doing
>> replaceWith.
>> I have solve the problem by using ".html"  instead of ".replaceWith".
>>
>> Thank you for your help. very appreciate it .
>>
>> Regards,
>> MH
>>
>>
>> On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos <omede...@gmail.com> wrote:
>>
>>> Hello Min,
>>>
>>> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>>>
>>> > hi oscar,
>>>
>>> > it works, but the problem in jquery load didn't refresh the page after
>>> I have loaded.
>>> > it will always use the outdated html.  I have tried to use ajaxsetup
>>> cache:false etc.
>>> > but seems like once it loaded. if form return validation error, even
>>> we have close
>>> > and call jquery load again. it will still static and show the last
>>> validation error.
>>>
>>> > how you solve this issue?  seems like more to javascript itself .
>>>
>>> I'm not sure why it isn't modifying the page correctly, because the
>>> following line should do it:
>>>
>>> $("#my-form").replaceWith(data.message);
>>>
>>> - Are you sure the form isn't being validated in the server-side?
>>> - Are you sure the request is being made to the server? (maybe an error
>>> occurs on the client-side and the request is never made).
>>> - Could you show us the entire code you are using?
>>>
>>> I suggest you doing two things:
>>> 1) Load the page, and before submitting the form, store the source
>>> code of the page. Then store it again once you submit it, so that you
>>> can compare both source codes.
>>> 2) Debug that jQuery code either with Chrome's Developer Tools, or
>>> Firebug for Firefox.
>>>
>>> > Regards,
>>> > MH
>>>
>>>
>>> --
>>> Oscar Mederos
>>> omede...@gmail.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
seems like .html has another problem.  it will duplicate itself (even not
seen in the screen).
but it did post Number of times when i submit the form.  still need to
struggling..bugs still
exist..

On Sat, May 5, 2012 at 2:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi Oscar,
>
> I think maybe it over some ajaxsetup({cache:false}) prevention when doing
> replaceWith.
> I have solve the problem by using ".html"  instead of ".replaceWith".
>
> Thank you for your help. very appreciate it .
>
> Regards,
> MH
>
>
> On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos <omede...@gmail.com> wrote:
>
>> Hello Min,
>>
>> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>>
>> > hi oscar,
>>
>> > it works, but the problem in jquery load didn't refresh the page after
>> I have loaded.
>> > it will always use the outdated html.  I have tried to use ajaxsetup
>> cache:false etc.
>> > but seems like once it loaded. if form return validation error, even we
>> have close
>> > and call jquery load again. it will still static and show the last
>> validation error.
>>
>> > how you solve this issue?  seems like more to javascript itself .
>>
>> I'm not sure why it isn't modifying the page correctly, because the
>> following line should do it:
>>
>> $("#my-form").replaceWith(data.message);
>>
>> - Are you sure the form isn't being validated in the server-side?
>> - Are you sure the request is being made to the server? (maybe an error
>> occurs on the client-side and the request is never made).
>> - Could you show us the entire code you are using?
>>
>> I suggest you doing two things:
>> 1) Load the page, and before submitting the form, store the source
>> code of the page. Then store it again once you submit it, so that you
>> can compare both source codes.
>> 2) Debug that jQuery code either with Chrome's Developer Tools, or
>> Firebug for Firefox.
>>
>> > Regards,
>> > MH
>>
>>
>> --
>> Oscar Mederos
>> omede...@gmail.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
hi Oscar,

I think maybe it over some ajaxsetup({cache:false}) prevention when doing
replaceWith.
I have solve the problem by using ".html"  instead of ".replaceWith".

Thank you for your help. very appreciate it .

Regards,
MH

On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos <omede...@gmail.com> wrote:

> Hello Min,
>
> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>
> > hi oscar,
>
> > it works, but the problem in jquery load didn't refresh the page after I
> have loaded.
> > it will always use the outdated html.  I have tried to use ajaxsetup
> cache:false etc.
> > but seems like once it loaded. if form return validation error, even we
> have close
> > and call jquery load again. it will still static and show the last
> validation error.
>
> > how you solve this issue?  seems like more to javascript itself .
>
> I'm not sure why it isn't modifying the page correctly, because the
> following line should do it:
>
> $("#my-form").replaceWith(data.message);
>
> - Are you sure the form isn't being validated in the server-side?
> - Are you sure the request is being made to the server? (maybe an error
> occurs on the client-side and the request is never made).
> - Could you show us the entire code you are using?
>
> I suggest you doing two things:
> 1) Load the page, and before submitting the form, store the source
> code of the page. Then store it again once you submit it, so that you
> can compare both source codes.
> 2) Debug that jQuery code either with Chrome's Developer Tools, or
> Firebug for Firefox.
>
> > Regards,
> > MH
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
hi oscar,

it works, but the problem in jquery load didn't refresh the page after I
have loaded.
it will always use the outdated html.  I have tried to use ajaxsetup
cache:false etc.
but seems like once it loaded. if form return validation error, even we
have close
and call jquery load again. it will still static and show the last
validation error.

how you solve this issue?  seems like more to javascript itself .

Regards,
MH

On Fri, May 4, 2012 at 11:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi oscar,
>
> Thank you!!! that is awesome! i not even need to manipulate the form using
> output data json!
> thanks! but ,  $("xxx").live  really is important...
>
>
> Regards,
> MH
>
>
> On Fri, May 4, 2012 at 4:56 PM, Oscar Mederos <omede...@gmail.com> wrote:
>
>> Hello Min,
>>
>> On Friday, May 4, 2012, 10:14:46 AM, you wrote:
>>
>> > hi oscar,
>>
>> > how do you make use of the particular method to be able to render
>> > the form only? as you said make use of the
>> > https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and
>> > it able to render the form instead of page?
>> > because i'm using kurtis method, if any validation error, i
>> > retrieve the data from javascript and manipulate the
>> > output in html only.
>>
>> What I usually do is the following:
>> - Place  the  content  of  my  form  in a separate template file (eg.
>> password-form.html)
>> - Using jQuery, I do something like:
>>
>> //Override the behavior of the 'submit' event of the form.
>> //Very important to use 'live' instead of 'click'. Otherwise,
>> //if we change the HTML of the form, this function won't be triggered
>> //next time we submit the form.
>> $("#my-form").live('submit', function(e) {
>>e.preventDefault();
>>$.ajax({
>>type: "post",
>>//DRY. I suppose you already have the url where
>>//you want to make the POST request in the "action"
>>//tag of the 
>>url: $("#my-form").attr("action"),
>>//This automatically get all the values from the
>>//inputs in the form (eg. a=1=2)
>>data: $("#my-form").serialize(),
>>dataType: "json",
>>success: function(data) {
>>//If there was an error...
>>if (data.error == 1) {
>>//All we have to do is replace the body of
>>//the .. with the new HTML
>>//rendered value of the form returned from
>>//the server
>>$("#my-form").replaceWith(data.message);
>>}
>>else {
>>//Do whatever you want here
>>}
>>}
>>});
>>});
>>
>> 'data' is what the view should return. What I usually do is the
>> following:
>> * If there was an error validating the form, then:
>>  - "data.error" will be 1
>>  - "data.message" will have the form rendered
>> * If the form was validated without problems
>>  - "data.error" will be 0
>>  - "data.message" will have some success message (eg. "Your password
>>  was changed successfully).
>>
>> - Now, in the view... how do I return the rendered form as HTML?
>>
>> The "password-form.html" template should look like:
>>
>> 
>>  {% csrf_token %}
>>  ...
>> 
>>
>> And the code of the view could be something like the following (of
>> course, checking that the request method was POST, etc).
>>
>> def view(request):
>># Create the bounded form (as you usually do)
>>f = MyForm(request.POST)
>>if form.is_valid():
>>   form.save()
>>   d = {'error': 0, 'message': 'Some success message'}
>>else:
>>   d = {'error': 1}
>>   # Here we render the entire HTML text of the form. You can pass
>>   # anything you want in the context...
>>   form_html = render_to_string('password-form.html',...,
>> context_instance=RequestContext(request))
>>   d['message'] = form_html
>>response = simplejson.dumps(d)
>>return HttpResponse(

Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
hi oscar,

Thank you!!! that is awesome! i not even need to manipulate the form using
output data json!
thanks! but ,  $("xxx").live  really is important...


Regards,
MH

On Fri, May 4, 2012 at 4:56 PM, Oscar Mederos <omede...@gmail.com> wrote:

> Hello Min,
>
> On Friday, May 4, 2012, 10:14:46 AM, you wrote:
>
> > hi oscar,
>
> > how do you make use of the particular method to be able to render
> > the form only? as you said make use of the
> > https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and
> > it able to render the form instead of page?
> > because i'm using kurtis method, if any validation error, i
> > retrieve the data from javascript and manipulate the
> > output in html only.
>
> What I usually do is the following:
> - Place  the  content  of  my  form  in a separate template file (eg.
> password-form.html)
> - Using jQuery, I do something like:
>
> //Override the behavior of the 'submit' event of the form.
> //Very important to use 'live' instead of 'click'. Otherwise,
> //if we change the HTML of the form, this function won't be triggered
> //next time we submit the form.
> $("#my-form").live('submit', function(e) {
>e.preventDefault();
>$.ajax({
>type: "post",
>//DRY. I suppose you already have the url where
>//you want to make the POST request in the "action"
>//tag of the 
>url: $("#my-form").attr("action"),
>//This automatically get all the values from the
>//inputs in the form (eg. a=1=2)
>data: $("#my-form").serialize(),
>dataType: "json",
>success: function(data) {
>//If there was an error...
>if (data.error == 1) {
>//All we have to do is replace the body of
>//the .. with the new HTML
>//rendered value of the form returned from
>//the server
>$("#my-form").replaceWith(data.message);
>}
>else {
>//Do whatever you want here
>}
>}
>});
>});
>
> 'data' is what the view should return. What I usually do is the
> following:
> * If there was an error validating the form, then:
>  - "data.error" will be 1
>  - "data.message" will have the form rendered
> * If the form was validated without problems
>  - "data.error" will be 0
>  - "data.message" will have some success message (eg. "Your password
>  was changed successfully).
>
> - Now, in the view... how do I return the rendered form as HTML?
>
> The "password-form.html" template should look like:
>
> 
>  {% csrf_token %}
>  ...
> 
>
> And the code of the view could be something like the following (of
> course, checking that the request method was POST, etc).
>
> def view(request):
># Create the bounded form (as you usually do)
>f = MyForm(request.POST)
>if form.is_valid():
>   form.save()
>   d = {'error': 0, 'message': 'Some success message'}
>else:
>   d = {'error': 1}
>   # Here we render the entire HTML text of the form. You can pass
>   # anything you want in the context...
>   form_html = render_to_string('password-form.html',...,
> context_instance=RequestContext(request))
>   d['message'] = form_html
>response = simplejson.dumps(d)
>return HttpResponse(response, mimetype='application/json')
>
> I wrote all of it in the editor of my email client, so if something
> does not work, just let me know.
>
> Again, very important to use the snippet provided in
> https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax
>
>
> > Regards,
> > MH
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
hi oscar,

how do you make use of the particular method to be able to render the form
only? as you said make use of the
https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and it able
to render the form instead of page?
because i'm using kurtis method, if any validation error, i retrieve the
data from javascript and manipulate the
output in html only.

Regards,
MH

On Fri, May 4, 2012 at 1:58 AM, Oscar Mederos  wrote:

> Hello Kurtis,
>
> On Thursday, May 3, 2012, 3:16:38 PM, you wrote:
>
> > Here's something I do.
>
> > I have a page where I include {% csrf_token %} and another field.
> > Then I do a simple JQuery .post() call.
>
> > Note, I've tried to pull out a bunch of stuff that isn't specific
> > to the call. It's untested in this form but should work. I tried to
> > include comments to help you understand what's going on.
>
> > 
> > $('div.theme_image, div.theme_name').on("click", function(event) {
> >
> > // Used later to access 'this' (the calling object)
> > var theme = this;
> >
> > // Prepare our AJAX Call.
> > url = '{% url fireflie.wizard.api.choose_theme %}'; // The URL to
> the View we're posting to.
>
> > // Building the POST data here.
> > data = {
> > theme_id: $(this).siblings('input').attr('value'),
> > csrfmiddlewaretoken:
> > $('input[name=csrfmiddlewaretoken]').attr('value')
> > };
> >
> > ...
> >
> > });
> > 
>
> Hello,
>
> Another good option for passing the csrf token is the following one:
> https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax.
>
> That helped me a lot, because sometimes you need to render your form
> again if it contains errors, and in that case, if you submit it again,
> the csrf token won't get updated correctly.
>
> Just imagine the case where the user wants to change his password:
> - He clicks on "Change password"
> - A modal form (dialog) appears
> - The user clicks on "Submit" and he didn't enter the two passwords
> correctly.
> - The form is rendered again (what I usually do is replace the
> .. content with the some HTML returned by the server in
> the AJAX response). That HTML usually is the rendered form, so that I
> don't need to go for each field and set the errors manually using JS.
>
> > Good luck!
> > -Kurtis Mullins
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
Thanks! kurtis, it did helps me. but, to render the form once it return
validation error. i need to use javascript returned value and
manipulate the form.
is there any refresh form content instead of i need to base on returned
value and manual add the error message?

On Thu, May 3, 2012 at 1:16 PM, Kurtis Mullins <kurtis.mull...@gmail.com>wrote:

> Here's something I do.
>
> I have a page where I include {% csrf_token %} and another field. Then I
> do a simple JQuery .post() call.
>
> Note, I've tried to pull out a bunch of stuff that isn't specific to the
> call. It's untested in this form but should work. I tried to include
> comments to help you understand what's going on.
>
> 
> $('div.theme_image, div.theme_name').on("click", function(event) {
>
> // Used later to access 'this' (the calling object)
> var theme = this;
>
> // Prepare our AJAX Call.
> url = '{% url fireflie.wizard.api.choose_theme %}'; // The URL to the
> View we're posting to.
>
> // Building the POST data here.
> data = {
> theme_id: $(this).siblings('input').attr('value'),
> csrfmiddlewaretoken:
> $('input[name=csrfmiddlewaretoken]').attr('value')
> };
>
> // Post Data to the Server
> var jqxhr = $.post(url, data, function(data) {
>
> // Do something in here on Success
> // In my example, I wanted to manipulate the calling object,
> // so it would be "theme" here. If you try to use "this", it won't
> work.
>
> });
>
> // On Error:
> jqxhr.error(function() {
>
>   // Do something in here in the case of errors.
>
> });
>
> });
> 
>
> Good luck!
> -Kurtis Mullins
>
> On Thu, May 3, 2012 at 1:46 PM, Bill Freeman <ke1g...@gmail.com> wrote:
>
>> AJAX
>>
>> You may require a separate view, but maybe not.
>>
>> If you search for jQuery and AJAX there should be samples.
>>
>> On 5/3/12, Min Hong Tan <tan.dja...@gmail.com> wrote:
>> > is there any sample that i can refer to do the ajax style form post
>> > without refresh the whole page?
>> > or backend form.save validation without refresh my form?
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



jquery form post without refresh the page

2012-05-03 Thread Min Hong Tan
is there any sample that i can refer to do the ajax style form post
without refresh the whole page?
or backend form.save validation without refresh my form?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to pass the username into a parameter in the views.py

2010-01-24 Thread min
Thank you!

On Jan 25, 11:51 am, Sam Lai <samuel@gmail.com> wrote:
> 2010/1/25 min <inuyasha...@gmail.com>:
>
> > Hi, everyone.
>
> > In the first place, I will login to access a web page by my "usename"
> > When I signed in, how to send my "username" into a parmaeter in the
> > views.py
>
> Look 
> herehttp://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-w...
>
> Once you've done that...
>
> > @login_required
> > def new_page(request):
>
> >    #how to get the username?
>
>       user = request.user
>
> >    form = newForm()
> >    variables = RequestContext(request, {'form': form})
> >    return render_to_response('new_page.html', variables)
>
> > thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to pass the username into a parameter in the views.py

2010-01-24 Thread min
Hi, everyone.

In the first place, I will login to access a web page by my "usename"
When I signed in, how to send my "username" into a parmaeter in the
views.py


@login_required
def new_page(request):

#how to get the username?

form = newForm()
variables = RequestContext(request, {'form': form})
return render_to_response('new_page.html', variables)

thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django and jQuery trouble

2009-02-09 Thread min

Hi, everyone.

I have a question for the following example.

Firstly, in the view.py:

def test_1(request, zipcode, pro):
  if zipcode == 'a' and pro == 'b':
city = 'c'
  else:
city = ''

  return HttpResponse(city)

def test_0(request):
  return render_to_response('test_0.html', {})
-
Then, in the test_0.html




Register form


  function getZipData() {
var zipcode = $('#zip').val();
var pro = $('#pro').val();
$.get('<a  rel="nofollow" href="http://127.0.0.1/ajax/test_1/">http://127.0.0.1/ajax/test_1/</a>' + zipcode + '&' + pro +
'/' , function(data) {
  $('#city').attr({'value':data});
});
  }





Pro:
Zip:
City:





--
In the urls.py

(r'^ajax/test_0/$', test_0),
(r'^ajax/test_1/(\S+)/$', test_1),
---
When I input b to the Pro inputbox and a to the Zip inputbox, and
click the done button, the firebug displays :500 Interserver Error

I think there are some problem with the  $.get('http://127.0.0.1/ajax/
test_1/' + zipcode + '&' + pro +  '/' , function(data) {$('#city').attr
({'value':data}); }); OR

def test_1(request, zipcode, pro):
  if zipcode == 'a' and pro == 'b':
city = 'c'
  else:
city = ''

  return HttpResponse(city)

Could you please give me some idea?

thanks
min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: request.GET Problem

2009-02-05 Thread min

Yes, thanks!

On Feb 6, 1:19 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Thu, 2009-02-05 at 17:22 -0800, min wrote:
>
> [...]
>
>
>
>
>
> > If use request.GET['selectM'].strip() in the following example, we can
> > only get the the 'value' of selected item.
>
> > 
> > 
> > 
> >         
> >                
> >                bbb
> >                ccc
> >                ddd
> >               
> >        
> > 
> > 
> > 
>
> > Is there any way to get both value and text from the SelectMultiple
> > widget the in the views.py?
>
> No, because HTML forms don't work that way. Only the value of the
> "value" attribute is submitted. You (the page designer) already know
> what the corresponding text for that option is, so the form shouldn't
> need to tell you about it again. It submits the minimum necessary.
>
> Regards,
> malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: request.GET Problem

2009-02-05 Thread min

Thanks a lot!

Regard
min

On Feb 6, 12:49 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Feb 5, 2009 at 8:47 PM, min <inuyasha...@gmail.com> wrote:
>
> > Ok, Thanks!
>
> > Another thing is that: I can only get one value by request.GET
> > ['selectM'].strip(), when I select two or more options in the
> > SelectMultiple widget.
>
> > For example, if I selected 'test1' and 'test2' in the SelectMultiple
> > widget, the value in the "request.GET['selectM'].strip()" is only
> > 'test2'.
>
> > If I want get all the values which I have selected, how to do that?
>
> > On Feb 6, 12:24 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> > > On Thu, Feb 5, 2009 at 8:22 PM, min <inuyasha...@gmail.com> wrote:
>
> > > > Hi.
>
> > > > In the following templates file, we can get the value of zip by using
> > > > ' request.GET['zip'].strip()' in the views.py
> > > > 
> > > > 
> > > > 
> > > >        
> > > >             Zip
> > > >             
> > > >        
> > > > 
> > > > 
>
> > > > However, if the 'zip' input was changed into a SelectMultiple widget,
> > > > like  how to get both the  value and option from that widget.
>
> > > > If use request.GET['selectM'].strip() in the following example, we can
> > > > only get the the 'value' of selected item.
>
> > > > 
> > > > 
> > > > 
> > > >        
> > > >               
> > > >               bbb
> > > >               ccc
> > > >               ddd
> > > >              
> > > >       
> > > > 
> > > > 
> > > > 
>
> > > > Is there any way to get both value and text from the SelectMultiple
> > > > widget the in the views.py?
>
> > > > thanks
>
> > > I don't believe so, the way HTTP works with the browser is that it only
> > > POSTs the value, fyi you might want to look at django.forms since it
> > saves
> > > you from worrying about this stuff.
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> request.GET.getlist('field') returns a list with all the values.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: request.GET Problem

2009-02-05 Thread min

Ok, Thanks!

Another thing is that: I can only get one value by request.GET
['selectM'].strip(), when I select two or more options in the
SelectMultiple widget.

For example, if I selected 'test1' and 'test2' in the SelectMultiple
widget, the value in the "request.GET['selectM'].strip()" is only
'test2'.

If I want get all the values which I have selected, how to do that?





On Feb 6, 12:24 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Feb 5, 2009 at 8:22 PM, min <inuyasha...@gmail.com> wrote:
>
> > Hi.
>
> > In the following templates file, we can get the value of zip by using
> > ' request.GET['zip'].strip()' in the views.py
> > 
> > 
> > 
> >        
> >             Zip
> >             
> >        
> > 
> > 
>
> > However, if the 'zip' input was changed into a SelectMultiple widget,
> > like  how to get both the  value and option from that widget.
>
> > If use request.GET['selectM'].strip() in the following example, we can
> > only get the the 'value' of selected item.
>
> > 
> > 
> > 
> >        
> >               
> >               bbb
> >               ccc
> >               ddd
> >              
> >       
> > 
> > 
> > 
>
> > Is there any way to get both value and text from the SelectMultiple
> > widget the in the views.py?
>
> > thanks
>
> I don't believe so, the way HTTP works with the browser is that it only
> POSTs the value, fyi you might want to look at django.forms since it saves
> you from worrying about this stuff.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



request.GET Problem

2009-02-05 Thread min

Hi.

In the following templates file, we can get the value of zip by using
' request.GET['zip'].strip()' in the views.py




 Zip
 




However, if the 'zip' input was changed into a SelectMultiple widget,
like  how to get both the  value and option from that widget.

If use request.GET['selectM'].strip() in the following example, we can
only get the the 'value' of selected item.





   
   bbb
   ccc
   ddd
  
   




Is there any way to get both value and text from the SelectMultiple
widget the in the views.py?


thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trouble with Django and jQuery

2009-02-05 Thread min

Ok, I will try this way.

Thank a lot!


On Feb 5, 11:50 pm, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On Feb 5, 12:19 pm, min <inuyasha...@gmail.com> wrote:
>
>
>
>
>
> > Hi, everyone.
>
> > I'm learing Django now. Currently, I have a problem with Django and
> > jQuery. The detail is that:
>
> > Firstly, I have a form in the forms.py:
>
> > class TestForm(forms.Form):
> >     name = forms.CharField( max_length=30 )
>
> > Then, in the views.py:
>
> > def Test_page(request):
> >     form = TestForm()
> >     result= ''
> >     if request.GET.has_key('name'):
> >         query = request.GET['name'].strip()
> >         if query:
> >             form = TestForm({'name': query})
> >             result= ''
> >     variables = RequestContext(request, {
> >         'form': form,
> >         'result': result
> >          })
> >     return render_to_response('Test.html', variables)
>
> > I'd like to use the 'result' parameter in the jQuery script in the
> > Test.html, when the user inputs some characters in the name field and
> > click the sumbit button.
>
> > The problem is that, when I use  var y = "{{result}}" by jQuery
> > function, the real value in the y is NOT '' which I defined in the
> > views.py. By contrast, The real value for y is {{result}}.
>
> > However, if I only use the original javascript script in the Test.html
> > by var x ="{{result}}", the real vaule in the x is ''.
>
> > Do you know how to use the 'result' parameter in the jQuery function?
>
> > thank you very much!
>
> The external jQuery script doesn't go through Django, so obviously the
> template variables aren't parsed. As you have discovered, you can put
> javascript in the template so that it is parsed. So you already have
> the answer to your question: use a small script within your template,
> which sets the values you need from the context and makes them
> available as global javascript variables. Then your external jQuery
> script will be able to access the global JS variables which will have
> the correct values.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Trouble with Django and jQuery

2009-02-05 Thread min

Hi, everyone.

I'm learing Django now. Currently, I have a problem with Django and
jQuery. The detail is that:

Firstly, I have a form in the forms.py:

class TestForm(forms.Form):
name = forms.CharField( max_length=30 )

Then, in the views.py:

def Test_page(request):
form = TestForm()
result= ''
if request.GET.has_key('name'):
query = request.GET['name'].strip()
if query:
form = TestForm({'name': query})
result= ''
variables = RequestContext(request, {
'form': form,
'result': result
 })
return render_to_response('Test.html', variables)

I'd like to use the 'result' parameter in the jQuery script in the
Test.html, when the user inputs some characters in the name field and
click the sumbit button.

The problem is that, when I use  var y = "{{result}}" by jQuery
function, the real value in the y is NOT '' which I defined in the
views.py. By contrast, The real value for y is {{result}}.

However, if I only use the original javascript script in the Test.html
by var x ="{{result}}", the real vaule in the x is ''.

Do you know how to use the 'result' parameter in the jQuery function?

thank you very much!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Not working. Still the same problem( when button is clicked, the text
of "This is a test" will display in the iframe for one second, and
then disappear.).

On Feb 2, 12:55 pm, "Will Matos" <w...@tcdi.com> wrote:
> Onclick="test();submit();"
> Will Matos
> TCDI
> Dir. of Tech. Sales
>
>
>
> - Original Message -
> From: django-users@googlegroups.com <django-users@googlegroups.com>
> To: Django users <django-users@googlegroups.com>
> Sent: Sun Feb 01 20:54:32 2009
> Subject: Re: trouble with Django and javascript
>
> If I use Onclick="submit();", how to add the javascript function " test
> ()" to that buttom?
>
> thanks
>
> On Feb 2, 11:58 am, "Will Matos" <w...@tcdi.com> wrote:
> > Onclick="submit();"
> > Will Matos
> > TCDI
> > Director of Technical Sales
> > 4510 Weybridge Lane
> > Greensboro, NC  27407
> > 336.232.5832 office
> > 336.232.5850 fax
> > 336.414.0467 mobile  
>
> > - Original Message -
> > From: django-users@googlegroups.com <django-users@googlegroups.com>
> > To: Django users <django-users@googlegroups.com>
> > Sent: Sun Feb 01 19:52:49 2009
> > Subject: Re: trouble with Django and javascript
>
> > Thanks for you reply.
>
> > However, if I change the 'submit' to button, how can I submit the form
> > to the server?
>
> > Regards
> > min
>
> > On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> > > In addition to displaying the message, it's also submitting the form,
> > > so you see the text for a second and then the form reloads.
>
> > > Change the  instead of "submit" and see if that 
> > > helps.
>
> > > Todd
>
> > > On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > > > First I  have a form:
>
> > > > class TestForm(forms.Form):
> > > >  name = forms.CharField( max_length=30 )
> > > >  age = forms.CharField( max_length=30 )
>
> > > > Then in the views.py:
>
> > > > def Test_page(request):
>
> > > >  form = TestForm()
> > > >  variables = RequestContext(request, {
> > > >    'form': form,
> > > >  })
> > > >  return render_to_response('Test.html', variables)
>
> > > > In the temlates file, I want to add a iframe and a submit button. When
> > > > the submit button was clicked, some word will appear in the iframe.
> > > > The following code is the Test.html:
>
> > > > 
> > > > Test Result Page
> > > > 
> > > >      
> > > >              function test(){
> > > >                              var iframe = document.getElementById
> > > > ("test");
> > > >                              var d = iframe.contentDocument;
> > > >                              d.body.innerHTML = "This is a test";
> > > >                              }
> > > >      
> > > > 
> > > > 
> > > >   
> > > >        Name:{{form.name}}
> > > >        age: {{form.age}}
> > > >        
> > > >        
> > > >   
> > > > 
> > > > 
>
> > > > Now, the problem is that, when I clicked the submit button, the text
> > > > of "This is a test" will display in the iframe for one second, and
> > > > then disappear. Is there any one know what's wrong with my code?
>
> > > > thanks
> > > > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

If I use Onclick="submit();", how to add the javascript function " test
()" to that buttom?

thanks

On Feb 2, 11:58 am, "Will Matos" <w...@tcdi.com> wrote:
> Onclick="submit();"
> Will Matos
> TCDI
> Director of Technical Sales
> 4510 Weybridge Lane
> Greensboro, NC  27407
> 336.232.5832 office
> 336.232.5850 fax
> 336.414.0467 mobile  
>
>
>
> - Original Message -
> From: django-users@googlegroups.com <django-users@googlegroups.com>
> To: Django users <django-users@googlegroups.com>
> Sent: Sun Feb 01 19:52:49 2009
> Subject: Re: trouble with Django and javascript
>
> Thanks for you reply.
>
> However, if I change the 'submit' to button, how can I submit the form
> to the server?
>
> Regards
> min
>
> On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> > In addition to displaying the message, it's also submitting the form,
> > so you see the text for a second and then the form reloads.
>
> > Change the  instead of "submit" and see if that 
> > helps.
>
> > Todd
>
> > On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > > First I  have a form:
>
> > > class TestForm(forms.Form):
> > >  name = forms.CharField( max_length=30 )
> > >  age = forms.CharField( max_length=30 )
>
> > > Then in the views.py:
>
> > > def Test_page(request):
>
> > >  form = TestForm()
> > >  variables = RequestContext(request, {
> > >    'form': form,
> > >  })
> > >  return render_to_response('Test.html', variables)
>
> > > In the temlates file, I want to add a iframe and a submit button. When
> > > the submit button was clicked, some word will appear in the iframe.
> > > The following code is the Test.html:
>
> > > 
> > > Test Result Page
> > > 
> > >      
> > >              function test(){
> > >                              var iframe = document.getElementById
> > > ("test");
> > >                              var d = iframe.contentDocument;
> > >                              d.body.innerHTML = "This is a test";
> > >                              }
> > >      
> > > 
> > > 
> > >   
> > >        Name:{{form.name}}
> > >        age: {{form.age}}
> > >        
> > >        
> > >   
> > > 
> > > 
>
> > > Now, the problem is that, when I clicked the submit button, the text
> > > of "This is a test" will display in the iframe for one second, and
> > > then disappear. Is there any one know what's wrong with my code?
>
> > > thanks
> > > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

Regards
min

On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

Regards
min

On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

Regards
min

On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Thanks for you reply.

However, if I change the 'submit' to button, how can I submit the form
to the server?

On Feb 2, 11:34 am, "Todd O'Bryan" <toddobr...@gmail.com> wrote:
> In addition to displaying the message, it's also submitting the form,
> so you see the text for a second and then the form reloads.
>
> Change the  instead of "submit" and see if that 
> helps.
>
> Todd
>
>
>
> On Sun, Feb 1, 2009 at 6:05 PM, min <inuyasha...@gmail.com> wrote:
>
> > First I  have a form:
>
> > class TestForm(forms.Form):
> >  name = forms.CharField( max_length=30 )
> >  age = forms.CharField( max_length=30 )
>
> > Then in the views.py:
>
> > def Test_page(request):
>
> >  form = TestForm()
> >  variables = RequestContext(request, {
> >    'form': form,
> >  })
> >  return render_to_response('Test.html', variables)
>
> > In the temlates file, I want to add a iframe and a submit button. When
> > the submit button was clicked, some word will appear in the iframe.
> > The following code is the Test.html:
>
> > 
> > Test Result Page
> > 
> >      
> >              function test(){
> >                              var iframe = document.getElementById
> > ("test");
> >                              var d = iframe.contentDocument;
> >                              d.body.innerHTML = "This is a test";
> >                              }
> >      
> > 
> > 
> >   
> >        Name:{{form.name}}
> >        age: {{form.age}}
> >        
> >        
> >   
> > 
> > 
>
> > Now, the problem is that, when I clicked the submit button, the text
> > of "This is a test" will display in the iframe for one second, and
> > then disappear. Is there any one know what's wrong with my code?
>
> > thanks
> > min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with Django and javascript

2009-02-01 Thread min

Besides, I use firefox.

On Feb 2, 10:05 am, min <inuyasha...@gmail.com> wrote:
> First I  have a form:
>
> class TestForm(forms.Form):
>   name = forms.CharField( max_length=30 )
>   age = forms.CharField( max_length=30 )
>
> Then in the views.py:
>
> def Test_page(request):
>
>   form = TestForm()
>   variables = RequestContext(request, {
>     'form': form,
>   })
>   return render_to_response('Test.html', variables)
>
> In the temlates file, I want to add a iframe and a submit button. When
> the submit button was clicked, some word will appear in the iframe.
> The following code is the Test.html:
>
> 
> Test Result Page
> 
>       
>               function test(){
>                               var iframe = document.getElementById
> ("test");
>                               var d = iframe.contentDocument;
>                               d.body.innerHTML = "This is a test";
>                               }
>       
> 
> 
>    
>         Name:{{form.name}}
>         age: {{form.age}}
>         
>         
>    
> 
> 
>
> Now, the problem is that, when I clicked the submit button, the text
> of "This is a test" will display in the iframe for one second, and
> then disappear. Is there any one know what's wrong with my code?
>
> thanks
> min
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



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

Regards
Min



On Jan 31, 8:48 am, Alex Robbins <alexander.j.robb...@gmail.com>
wrote:
> 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:
> <script>
> var x = {{ variable_to_insert_into_template }};
> 
>
> Your views.py should look like this:
> tags = ['fun', 'exciting', 'cool']
> from django.utils import simplejson
> variable_to_insert_into_template = simplejson.dumps(tags)
>
> And make sure you "shove" variable_to_insert into the context like
> Malcolm explained. (Possibly using that js filter to make sure your js
> comes through ok.)
>
> On Jan 30, 3:29 pm, min <inuyasha...@gmail.com> wrote:
>
>
>
> > 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 <alexander.j.robb...@gmail.com>
> > 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 variable_to_insert_into_template to the template and then just
> > > put {{variable_to_insert_into_template}} somewhere in your code.
>
> > > Just my 2 cents.
>
> > > On Jan 30, 10:42 am, Alex Robbins <alexander.j.robb...@gmail.com>
> > > wrote:
>
> > > > 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 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > > > wrote:
>
> > > > > 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 = False
> > > > > >     variable = ''
> > > > > >     if request.GET.has_key('name'):
> > > > > >         show_results = True
> > > > > >         query = request.GET['name'].strip()
> > > > > >         variable  = 'custom value'
> > > > > >     variables = RequestContext(request, {
> > > > > >         'form': form,
> > > > > >         'show_results': show_results,
> > > > > >         'variable': variable
> > > > > >          })
> > > > > >     return render_to_response('Test.html', variables)
>
> > > > > > I know the value of variable can be accessed by using {{variable}} 
> > > > > > in
> > > > > > the Test.html. However, if I want use the jQuery in the Test.html 
> > > > > > and
> > > > > > pass the value of this variable to the jQuery function, how to do
> > > > > > that?
>
> > > > > > I have tried: var x = $("variable").val(), and not succeed.
>
> > > > > The context dictionary you pass to render_to_response is used by
> > > > > render_to_response to produce a string. That string is what is sent 
> > > > > back
>

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 <alexander.j.robb...@gmail.com>
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 variable_to_insert_into_template to the template and then just
> put {{variable_to_insert_into_template}} somewhere in your code.
>
> Just my 2 cents.
>
> On Jan 30, 10:42 am, Alex Robbins <alexander.j.robb...@gmail.com>
> wrote:
>
>
>
> > 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 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > wrote:
>
> > > 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 = False
> > > >     variable = ''
> > > >     if request.GET.has_key('name'):
> > > >         show_results = True
> > > >         query = request.GET['name'].strip()
> > > >         variable  = 'custom value'
> > > >     variables = RequestContext(request, {
> > > >         'form': form,
> > > >         'show_results': show_results,
> > > >         'variable': variable
> > > >          })
> > > >     return render_to_response('Test.html', variables)
>
> > > > I know the value of variable can be accessed by using {{variable}} in
> > > > the Test.html. However, if I want use the jQuery in the Test.html and
> > > > pass the value of this variable to the jQuery function, how to do
> > > > that?
>
> > > > I have tried: var x = $("variable").val(), and not succeed.
>
> > > The context dictionary you pass to render_to_response is used by
> > > render_to_response to produce a string. That string is what is sent back
> > > to the browsers. The variables (parameters, whatever we want to call
> > > them) are shoved into the template -- in a nice way; they're made very
> > > comfortable -- and become static data in the final result. That is, they
> > > are *not* variables from the browser's perspective. Template rendering
> > > happens fully on the server side.
>
> > > If you want to access this data via Javascript, you first have to make
> > > it available as a Javascript variable in the template. For example, you
> > > could write this in your template (inside a script block).
>
> > >         var x = "{{ variable|escape_js }}";
>
> > > The {{...}} bit is converted to a string by the (server-side) template
> > > rendering. Then "x" is available to the browser-side Javascript. Clear
> > > as mud?
>
> > > Regards,
> > > Malcolm- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



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 <malc...@pointy-stick.com>
wrote:
> 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 = False
> >     variable = ''
> >     if request.GET.has_key('name'):
> >         show_results = True
> >         query = request.GET['name'].strip()
> >         variable  = 'custom value'
> >     variables = RequestContext(request, {
> >         'form': form,
> >         'show_results': show_results,
> >         'variable': variable
> >          })
> >     return render_to_response('Test.html', variables)
>
> > I know the value of variable can be accessed by using {{variable}} in
> > the Test.html. However, if I want use the jQuery in the Test.html and
> > pass the value of this variable to the jQuery function, how to do
> > that?
>
> > I have tried: var x = $("variable").val(), and not succeed.
>
> The context dictionary you pass to render_to_response is used by
> render_to_response to produce a string. That string is what is sent back
> to the browsers. The variables (parameters, whatever we want to call
> them) are shoved into the template -- in a nice way; they're made very
> comfortable -- and become static data in the final result. That is, they
> are *not* variables from the browser's perspective. Template rendering
> happens fully on the server side.
>
> If you want to access this data via Javascript, you first have to make
> it available as a Javascript variable in the template. For example, you
> could write this in your template (inside a script block).
>
>         var x = "{{ variable|escape_js }}";
>
> The {{...}} bit is converted to a string by the (server-side) template
> rendering. Then "x" is available to the browser-side Javascript. Clear
> as mud?
>
> Regards,
> Malcolm- Hide quoted text -
>
> - Show quoted text -

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



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_results = True
query = request.GET['name'].strip()
variable  = 'custom value'
variables = RequestContext(request, {
'form': form,
'show_results': show_results,
'variable': variable
 })
return render_to_response('Test.html', variables)

I know the value of variable can be accessed by using {{variable}} in
the Test.html. However, if I want use the jQuery in the Test.html and
pass the value of this variable to the jQuery function, how to do
that?

I have tried: var x = $("variable").val(), and not succeed.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---