简体   繁体   English

不以html形式将值传递给python cgi

[英]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 我有一个Python .py cgi脚本,它可以单独正常工作,但是当我尝试通过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 在脚本中,myprogram使用screen_name的值(现在为username1 )来获取username1的详细信息,并且工作正常

The problem comes up when I try to use a form to get info on other users like usernam2 or username3 etc 当我尝试使用表单获取其他用户(如usernam2或username3等)的信息时,就会出现问题

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 在我的html表单中,通过POST有一个名为关键字的字段名称,其中该字段的值称为用户名 。表单上的操作指向下面的此.py程序

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 我想在脚本中使用在表单中捕获的用户名的值,因此当您编写并提交用户名值时,.py脚本将screen_name用作表单中的值

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 ') 因此,如果表单现在具有关键字username2或username3,那么.py脚本将需要更改为details = myprogram.show_user(screen_name =' username1 ')

to details = myprogram.show_user(screen_name=' username2 ') 详细信息= myprogram.show_user(screen_name =' username2 ')

or to 或者

details = myprogram.show_user(screen_name=' username3 ') depending on the value inserted in the Form 详细信息= myprogram.show_user(screen_name =' username3 '),具体取决于表单中插入的值

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 在下面,这是我尝试执行的操作并且不起作用。它一直返回用户的值,而不是在表单中插入新值。我想要的是为screen_name提供在表单输入中找到的值,这可能是username1,username2等

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) user等于在表单中找到的找到的值,这是我编写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 当我像下面那样运行脚本时,没有错误,但是脚本没有从它刚刚执行的表单中获取值,而是为screen_name提供了它现在拥有的值,而不是Form中的值

The importance here is to have screen_name = to the value of what was written in the form 此处的重要性是让screen_name =形式的值

So I say screen_name = user where user = form.getvalue('username') 所以我说screen_name = user,其中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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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