开发者

Python CGI - GET form, typing in an address in browser giving the correct page

I'm trying to make a website using python with CGI. This website is very basic, all it has is login, logout and d开发者_运维百科isplay data from a database using sqlite.

I was wondering how would I create a hyperlink to a page displaying a message returned from the database using a GET form with no submit button? The hyperlink would be something like:

www.test.com/cgi-bin/test.py?message=id

Where the id is equal to an item returned from a list (which has the id and message) from a database. So when I type into the browser say, message=23, it will display that message on a page alone or when I create a hyperlink with the query string message=43, it will display the message with ID 43.

I've looked at this tutorial (Simple URL example: get method part): http://www.tutorialspoint.com/python/python_cgi_programming.htm

But I don't know how I would get rid of the submit button with the values being from the database and appended to the URL. (test.py?foo=bar)

Hopefully I have explained everything clearly.


A URL is a URL. It doesn't matter if you generate it by typing it in, clicking a link, or submitting a form (with method=GET).

<a href="http://www.test.com/cgi-bin/test.py?message=22">…</a>

Update based on the understanding that the question is actually:

How do I read the query string in a CGI script written in Python?

import cgi
form = cgi.FieldStorage()
messageid = form.getvalue("message")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜