简体   繁体   中英

Not passing values in a html form to a python cgi

I have a Python .py cgi script that is working fine alone but not when I try to put new values in via a Form

Below you will see how it basically looks when working alone

In the script, myprogram uses the value of screen_name which is now username1 in order to get details of username1 and it is working fine

The problem comes up when I try to use a form to get info on other users like usernam2 or username3 etc

Here you will see details of this working script

........................

details = myprogram.show_user(screen_name='**username1**')

print "content-type: text/html;charset=utf-8"
print
print"<html><head></head><body>"
print (details['followers'])
print "<br/>"
print (details['friends'])
print "<br/>"
print (details['name'])

............................

As I mentioned above The problem comes up when I try to use a form to capture a different username

In my html form , via POST there is a field name called keyword in which the value of the field is called username The Action on the form points to this .py program that is below

I want to use the value of the username captured in the Form in my script so when you write and submit the username value the .py script uses as screen_name the value in the Form

So if the form now has as keyword username2 or username3 then the .py script would need to change from details = myprogram.show_user(screen_name=' username1 ')

to details = myprogram.show_user(screen_name=' username2 ')

or to

details = myprogram.show_user(screen_name=' username3 ') depending on the value inserted in the Form

Below this is how I have tried to do it and does not work It keeps returning the value of user instead of a new value inserted in the form What I want is to give the screen_name the value found in the input of the Form, that could be username1, username2 etc etc

user is equal to the value found which was written in the form and is what I try to do when I write user=form.getvalue(username)

When I run the script like below there is no error but the script does not take the value from the form it just executes and gives screen_name the value it now has instead of the one in the Form

The importance here is to have screen_name = to the value of what was written in the form

So I say screen_name = user where user = form.getvalue('username')

BUt I need help because this is nort working

Thank you

Javier ............................

import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorage()

user = form.getvalue('username')

details = myprogram.show_user(screen_name='user')

print "content-type: text/html;charset=utf-8"
print
print"<html><head></head><body>"
print (details['followers'])
print "<br/>"
print (details['friends'])
print "<br/>"
print (details['screen'])

........................................

Thanks

不要将变量名放在引号中。

details = myprogram.show_user(screen_name=user)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM