瓶子运行脚本

问题描述 投票:0回答:1

我想在按下带有瓶子的按钮时运行脚本。但是我每次都会收到404错误。它在地址栏中显示localhost://File.py,但我不知道如何路由它。我对此很陌生。如果您能帮助我,我会很高兴。

app.py

    from bottle import *

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


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

File.py

#!/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>")

deneme.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>
python bottle
1个回答
1
投票

您不应该将cgicgitb与Bottle,Flask或任何其他Python网络框架一起使用。

尝试类似的东西

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")。

此外,请考虑使用Flask;它与Bottle的脉络相同,但更受欢迎且更易于维护。

© www.soinside.com 2019 - 2024. All rights reserved.