473,573 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get parameters from the URL

Hi all,

I'm a python noob so don't be mean :)
I have a URL like http://mySite.net?userID=398&age=28
I'm trying to create a new python script that is called when a user
click a button "Redirect". When a user clicks the "Redirect" button, I
want to send the user to either of the 2 pages, depending on the age of
the user (sent as a parameter using the URL).

What is the best way to
1. Read the URL and get the parameters (age=28 in this case)
2. Redirect the the user accordingly

I have done this kind of thing in a jsp/servlet environment but I have
no idea how to proceed in the Python world.

Any advice/example would help.

Regards,
Sohrab
Aug 21 '08 #1
1 1966
On Thu, 21 Aug 2008 10:04:35 +0530, Sohrab Pawar wrote:
I'm a python noob so don't be mean :) I have a URL like
http://mySite.net?userID=398&age=28 I'm trying to create a new python
script that is called when a user click a button "Redirect". When a user
clicks the "Redirect" button, I want to send the user to either of the 2
pages, depending on the age of the user (sent as a parameter using the
URL).

What is the best way to
1. Read the URL and get the parameters (age=28 in this case) 2. Redirect
the the user accordingly

I have done this kind of thing in a jsp/servlet environment but I have
no idea how to proceed in the Python world.
If you really got that string you can use the modules `urlparse` and
`cgi` to get the query part:

In [48]: url = 'http://mySite.net?user ID=398&age=28'

In [49]: urlparse.urlpar se(url)
Out[49]: ('http', 'mySite.net', '', '', 'userID=398&age =28', '')

In [50]: cgi.parse_qs(ur lparse.urlparse (url)[4])
Out[50]: {'age': ['28'], 'userID': ['398']}

But maybe you should read about the `cgi` module and how to use it.

Ciao,
Marc 'BlackJack' Rintsch
Aug 21 '08 #2

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

Similar topics

4
1636
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub UploadData(ByVal sender As Object, ByVal e As EventArgs) Dim MyConn As New
0
302
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub UploadData(ByVal sender As Object, ByVal e As EventArgs) Dim MyConn As New
14
3254
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself which one to pass and...
2
2622
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying to update a record, I get a "No value given for one or more parameters." error message. I use a Select with parameters and an Update with...
12
2657
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be avoided. I'd like to hear your various opinions on this matter.
0
7784
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...
0
8033
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5601
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5294
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...
1
2224
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
1
1316
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1044
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...

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.