单击HTML按钮时如何运行脚本(Python、瓶子)

单击HTML按钮时如何运行脚本(Python、瓶子),python,bottle,Python,Bottle,我想在按下瓶子按钮时运行脚本。但我每次都会收到404个错误。地址栏上写着localhost://File.py,但我不知道如何路由它 app.py File.py #/usr/bin/python 导入cgi,cgitb form=cgi.FieldStorage 用户名=形式[“用户名”]。值 emailaddress=表单[“emailaddress”]。值 打印(“内容类型:text/html\r\n\r\n”) 打印(“”) 打印(“”) 打印(“第一稿”) 打印(您不应该将cgi和cg

我想在按下瓶子按钮时运行脚本。但我每次都会收到404个错误。地址栏上写着localhost://File.py,但我不知道如何路由它

app.py File.py
#/usr/bin/python
导入cgi,cgitb
form=cgi.FieldStorage
用户名=形式[“用户名”]。值
emailaddress=表单[“emailaddress”]。值
打印(“内容类型:text/html\r\n\r\n”)
打印(“”)
打印(“”)
打印(“第一稿”)

打印(您不应该将
cgi
cgib
与瓶子、烧瓶或任何其他Python web框架一起使用

试试像这样的东西

from bottle import run, route, request

@route('/')
def home():
    return template('deneme.html')

@route('/foo')
def foo():
    return '%s %s' % (request.forms.username, request.forms.email)

run(host='localhost',port=8080)
(并将表单的操作更改为
action=“/foo”


也可以考虑使用烧瓶,它与瓶子是一样的,但更流行和更持久。

不应该使用CGI和CGITB与瓶子、烧瓶或任何其他Python Web框架。为什么?因为它们不会互操作。<代码> CGI < /代码>只用于原始CGI程序,如果你在Web框架下运行,它将处理CGI。put/output.那么我该怎么做呢?你能给我一个主意吗?你能为你的语句提供更多的细节或图片吗?地址栏上写着localhost://File.py,但我不知道如何发送它。
?我想如果其他人知道它是什么,并且可以看到当tton已单击。问题已更改。下面是新问题
#!/usr/bin/python
import cgi, cgitb
form =  cgi.FieldStorage


username = form["username"].value
emailaddress = form["emailaddress"].value



print("Content-type: text/html\r\n\r\n")
print( "<html>")
print("<head>")
print("<title>First Script</tittle>")
print("</head")
print("<body>")
print("<h3>This is HTML's Body Section</h3>")
print(username)
print(emailaddress)
print("</body>")
print("</html>")
<html>
  <head>
  <meta charset="UTF-8">
    <title>Document</title>

  </head>
  <body>
  <form action="File.py" method="post">
    username: <input type="text" name="username"/>
    <br />
    Email Adress: <input type="email" name="emailaddress"/>
<input type="submit" name="Submit">
    </form>
  </body>
</html>
from bottle import run, route, request

@route('/')
def home():
    return template('deneme.html')

@route('/foo')
def foo():
    return '%s %s' % (request.forms.username, request.forms.email)

run(host='localhost',port=8080)