473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1956
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?userID=398&age=28'

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

In [50]: cgi.parse_qs(urlparse.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
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...
0
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...
14
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...
2
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...
12
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.