Re: Can javascript call a python script?

2008-12-04 Thread Django Newbie

With AJAX you can.  Javascript is interpreted by the browser, and you 
want to call a serverside script.  Or you could do it as a form 
submission, but I assume you want it to happen without refreshing the 
page, so AJAX is how you would do that.

Eric wrote:
> Hello, this might be a silly question, but I'm wondering if javascript
> can call a python script, and if so, how?
>
> To elaborate, I'm trying to customize the admin change_list page so
> that editing can be done directly from the change_list, instead of
> clicking into the admin change_form page. To do this, I have a
> javascript that pops up a prompt box when an element in the
> change_list table is clicked. I'd then like to call a python script to
> modify that element in the database (since I don't believe the DB can
> be modified directly in the javascript).
>
> If this is unnecessary or just plain wrong, or if someone has a better
> way of editing items directly from the change_list, please let me
> know! Thanks much for the help.
> >   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can javascript call a python script?

2008-12-03 Thread Daniel Roseman

On Dec 4, 4:09 am, Eric <[EMAIL PROTECTED]> wrote:
> Hello, this might be a silly question, but I'm wondering if javascript
> can call a python script, and if so, how?
>
> To elaborate, I'm trying to customize the admin change_list page so
> that editing can be done directly from the change_list, instead of
> clicking into the admin change_form page. To do this, I have a
> javascript that pops up a prompt box when an element in the
> change_list table is clicked. I'd then like to call a python script to
> modify that element in the database (since I don't believe the DB can
> be modified directly in the javascript).
>
> If this is unnecessary or just plain wrong, or if someone has a better
> way of editing items directly from the change_list, please let me
> know! Thanks much for the help.

This is what AJAX is for. Get your Javascript to make a request to the
server via XMLHTTPRequest, or whatever shortcuts your library of
choice provides. The request should call a normal Django view which
does whatever you need in the usual way, and provides a response back
to the client-side Javascript either as XML, JSON or even ready-
formatted HTML.

So, using jQuery for example:
$('.myelement').click(function() {
$.post('/my-django-view/', {element: $(this).attr(id)}, function()
{
    whatever actions you want the js to do on response ...
 }
  }
);

--
DR
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can javascript call a python script?

2008-12-03 Thread Jeff Anderson
Eric wrote:
> Hello, this might be a silly question, but I'm wondering if javascript
> can call a python script, and if so, how?
>   
I believe Javascript can execute external commands, but I'm sure that
it'd be turned off entirely for security reasons. I wouldn't trust
client side code to modify my database any day.

It sounds like you're asking if Javascript can run a python script on
the server. Technically, any time a request is made to a webserver code
(including python scripts) can be run on the server, and Javascript can
make server requests. That's what Ajax is for. The javascript will send
a request to the server without reloading the page in the browser, and
can (optionally) change something in the loaded page based on data
received by the response, while the server can do whatever it wants–
including updating a database.


Hopefully this is helpful!

Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Can javascript call a python script?

2008-12-03 Thread Eric

Hello, this might be a silly question, but I'm wondering if javascript
can call a python script, and if so, how?

To elaborate, I'm trying to customize the admin change_list page so
that editing can be done directly from the change_list, instead of
clicking into the admin change_form page. To do this, I have a
javascript that pops up a prompt box when an element in the
change_list table is clicked. I'd then like to call a python script to
modify that element in the database (since I don't believe the DB can
be modified directly in the javascript).

If this is unnecessary or just plain wrong, or if someone has a better
way of editing items directly from the change_list, please let me
know! Thanks much for the help.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---