Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 26th, 2006, 12:07 AM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
GET/POST vars in Python

I just started learning Python, and I'm trying to figure out how to access GET/POST form variables. Anyone know? Thanks.
titaniumdecoy is offline   Reply With Quote
Old May 26th, 2006, 12:13 AM   #2
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
With... raw sockets? CherryPy? CGI?

...
Sane is offline   Reply With Quote
Old May 26th, 2006, 12:15 AM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
That sounds sorta complicated. Isn't there an easy way to do it? In PHP you can use $_GET['var'] or $_POST['var']...

EDIT: I believe this article covers what I was looking for.

Last edited by titaniumdecoy; May 26th, 2006 at 12:36 AM.
titaniumdecoy is offline   Reply With Quote
Old May 26th, 2006, 12:39 AM   #4
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
No... I was asking you what the medium was for attaining the arguments? Are you trying to do it
Quote:
Originally Posted by Sane
With... raw sockets? CherryPy? CGI?
I take it from that tutorial that you were using CGI. Just stick with a tutorial then, not much more to say. Good luck.
Sane is offline   Reply With Quote
Old May 26th, 2006, 1:26 AM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
I'm talking about getting information submitted to a script by an HTML form. If there's an easier/better way to do it than by using the CGI module, I'd be glad to hear about it.
titaniumdecoy is offline   Reply With Quote
Old May 26th, 2006, 1:30 AM   #6
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
I know that's what you're talking about, but it would have helped if you said what you're listening to the HTTP packets with. CherryPy, for example, makes this very easy for you. The POST/GET arguments come in directly as arguments to the functions you map to pages. http://cherrypy.org can teach you all about CherryPy.

Raw Sockets you would have to parse yourself. Not sure about CGI. Not aware of any other methods, other then the HTTP module that interfaces to the socket library.
Sane is offline   Reply With Quote
Old May 26th, 2006, 1:33 AM   #7
DaveQB
Newbie
 
DaveQB's Avatar
 
Join Date: Apr 2006
Location: Sydney
Posts: 14
Rep Power: 0 DaveQB is on a distinguished road
Send a message via ICQ to DaveQB Send a message via Skype™ to DaveQB
CGI module is the way to go. Its not too hard, very similiar to PHP besides the import statement.
DaveQB is offline   Reply With Quote
Old May 26th, 2006, 4:04 AM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by DaveQB
CGI module is the way to go. Its not too hard, very similiar to PHP besides the import statement.
CGI is the way to go only if you have no alternative. If your host restricts you to Python CGI, then that's what you have to use. If you have no such restriction, I can think of absolutely no advantage of using CGI.
Arevos is offline   Reply With Quote
Old May 26th, 2006, 6:45 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
CGI is the only alternative I have on my commercial host. I find it straightforward. Here's some snips:
print "Content-type: text/html\n\n"
import os
import cgitb; cgitb.enable()  #Debug aid to be removed later
import cgi
import re
import types
...
...
SERVER = os.environ
script = SERVER ['SCRIPT_NAME']
query = SERVER ['QUERY_STRING']
browser = SERVER ['HTTP_USER_AGENT']
ip = SERVER ['REMOTE_ADDR']
...
...
form = cgi.FieldStorage ()
page = form.getfirst ("page", "0-0")
...
That last statement gets the page field from the form or from a GET like "myurl?page=0-0&blah=blah". It gets the first, if there are more than one, and returns the second argument as a default if it isn't present.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 26th, 2006, 11:32 AM   #10
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Thanks DaWei.

Quote:
Originally Posted by Arevos
CGI is the way to go only if you have no alternative. If your host restricts you to Python CGI, then that's what you have to use. If you have no such restriction, I can think of absolutely no advantage of using CGI.
Why is CGI so bad? Would you suggest using CherryPy like Sane?
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC