473,725 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using python with HTML and parameters

Hi,

In java/jsp I can pass parameters to my python script on a webpage by doing
something like this:

http://somewhere.org/mypage.jsp?parm...&parm2=another

How do I do that with python?

Also would I need to import a special module so I could grab them off the
'line' (I' m not sure what you call it if its a command line, etc as its
coming via a 'get' or 'post' request via HTTP protocol.

On the webpage I am building I would like to pass parameters to python.

Thanks !
David Stockwell
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_______________ _______________ _______________ _______________ _____
FREE pop-up blocking with the new MSN Toolbar – get it now!
http://toolbar.msn.click-url.com/go/...ave/direct/01/
Jul 18 '05 #1
4 3547
David Stockwell schrieb:
In java/jsp I can pass parameters to my python script on a webpage by
doing something like this:

http://somewhere.org/mypage.jsp?parm...&parm2=another

How do I do that with python?


If your Python Script uses CGI it's

http://somewhere.org/mypage.py?parm1...&parm2=another

:) You have to parse the query string with cgi.parse().

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
eMail 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Jul 18 '05 #2
Peter Maas schrieb:
If your Python Script uses CGI it's

http://somewhere.org/mypage.py?parm1...&parm2=another


Correction: this URL does not depend on CGI, only the Python code.

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
eMail 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Jul 18 '05 #3
"David Stockwell" <wi*******@hotm ail.com> writes:
In java/jsp I can pass parameters to my python script on a webpage by
doing something like this:

http://somewhere.org/mypage.jsp?parm...&parm2=another
Call me picky <wink>, but that looks like a URL to me, not a piece of
Java code.

How do I do that with python?
If you mean, "how do I pass parameters to a Python CGI script?", then,
well, exactly the same way as to any other CGI script. A URL like the
one you give above, or HTTP POST data (or both).

Also would I need to import a special module so I could grab them off
the 'line' (I' m not sure what you call it if its a command line, etc
as its coming via a 'get' or 'post' request via HTTP protocol.


No, that's the web server's job.

However, if you're writing a CGI script that will handle, you may want
to make use of the standard library cgi module. And, if you're doing
anything more than a quick hack of a script, I'd advise dropping the
cgi module and using one of the many web frameworks available for
Python instead (eg. Quixote).

HTH
John
Jul 18 '05 #4
"David Stockwell" <wi*******@hotm ail.com> wrote in message news:<ma******* *************** *************** *@python.org>.. .
Hi,

In java/jsp I can pass parameters to my python script on a webpage by doing
something like this:

http://somewhere.org/mypage.jsp?parm...&parm2=another

How do I do that with python?
As others have inferred from this question, you're presumably looking
for a way of interpreting the URL's parameters within Python, right?
Also would I need to import a special module so I could grab them off the
'line' (I' m not sure what you call it if its a command line, etc as its
coming via a 'get' or 'post' request via HTTP protocol.
I believe "request parameters" is the best term to use here.
On the webpage I am building I would like to pass parameters to python.


Well, your URL will pass two parameters to a resource exposed as
"mypage.jsp " (which could actually be a Python script given the
appropriate Web server configuration, although I suppose you're using
a JSP resource as an example of how you'd do it with Java/JSP); these
parameters would be "parm1" and "parm2", and I suppose you'd use the
Java Servlet API methods getParameter or getParameterVal ues to get the
associated values which are "something" and "another" respectively for
the specified parameters.

Now, in Python, it really depends on your chosen technology as to how
you get those values. Anything vaguely based on the cgi module
(http://docs.python.org/lib/module-cgi.html) will require you to get
hold of a FieldStorage object and then to use the getvalue method on
it, although care has to be taken about the result and whether it's a
list or not (since you can have many values for a given parameter
name).

In WebStack (http://www.python.org/pypi?:action=d...ck&version=0.5)
I've tried to standardise this kind of thing, even converting
parameter values from POST requests to Unicode in order to remove
difficulties when actually using such values later on, but on matters
of standardisation the Web-SIG remains silent, so I wouldn't expect
the confusing situation to remedy itself any time soon.

Paul
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1568
by: Raymond Hettinger | last post by:
QOTW: "the DOM API is designed for consultants, not for humans or computers" -- Fredrik Lundh giving solace to a confused DOM API user QOTW: "Python enjoys making tradeoffs that drive *someone* crazy <wink>" -- Michael Hudson's signature line attributed to Tim Peters Discussion ---------- Alex Martelli shows the classic example for the "for-else"
0
6702
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
20
4068
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: li=;
0
1302
by: Cameron Laird | last post by:
QOTW: "If you don't have the time to be paranoid, try taking the time to straighten out identity theft." -- K. G. Schneider "The best way to make classes on the fly is generally to call the metaclass with suitable parameters (just like, the best way to make instances of any type is generally to call that type)." -- Alex Martelli What code is good to read? The Standard Library. The Indexed Packages. The Cheese Shop. Bit Torrent. ...
29
16562
by: 63q2o4i02 | last post by:
Hi, I'm interested in using python to start writing a CAD program for electrical design. I just got done reading Steven Rubin's book, I've used "real" EDA tools, and I have an MSEE, so I know what I *want* at the end of this; I just have never taken on a programming task of this magnitude. I've seen that some are using python as a utility language for existing CAD environments, and I've also found some guy who's writing a 2d drafting...
1
311
by: Cameron Laird | last post by:
QOTW: "sing Python is not programming, it IS a fun!" - Tolga "The reason for making complex a builtin is _not_ to ease a single program, but to create a convention allowing different modules which operate on complex numbers to communicate." -Scott David Daniels Komodo 4.0 debuted at last week's OSCON: http://www.activestate.com/komodo/beta
14
5522
by: mistral | last post by:
Need compile python code, source is in html and starts with parameters: #!/bin/sh - "exec" "python" "-O" "$0" "$@" I have installed ActivePython for windows.
4
1780
by: pmcgover | last post by:
I enjoyed Paul Barry's September article in Linux Journal entitled, "Web Reporting with MySQL, CSS and Perl". It provides a simple, elegant way to use HTML to display database content without any sql markup in the cgi script. The cgi script simply calls the Mysql command line with the HTML option (-H) and the SQL script file directed to that command. This provides complete separation of the markup from the sql code. The plain vanila...
14
2087
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in python. It's free at http://pnk.com and it is a web timesheet for project accounting
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.