将数据发送到python Flask

时间:2013-10-02 02:40:24

标签: python web flask

我写了两个python文件,第一个是从API打印出一个字符串,另一个是使用flask来构建一个网站。所以在第一个文件中,我得到一个变量并打印出来。

firstevent = events['items'][1]['end']

在python flask中,我想发送第一个,但第一次看起来像是“null”

app = Flask(__name__)



@app.route("/")
def index():
    return """Hello!<br/><br/>
    <a href='/form'>Visit form page</a>"""


# Second Page Route
@app.route("/page2")
def page2():
  return """<html><body>
  <h2></h2>
    <p></p>
    </body></html>"""


# new route will accept both a GET and POST request from the client (web browser)
@app.route("/form", methods=["GET","POST"])
def simpleform():

    # Did the client make a POST request?
    if request.method == "POST":

        # get the form data submitted and store it in a variable
        user_name = request.form.get('user_name', 'firstevent')

        # return custom HTML using the user submitted data
        return "<html><body><h3>Hello %s! What an interesting name.</h3><br><a href='/form'>back to form</a></body><html>" % user_name

    else:

        # client made a GET request for '/form'
        # return a simple HTML form that POSTs to itself
        return """<html><body>
        <form action="/form" method="POST">
            What's your name? <input type="text" name="user_name" id="user_name"/>
            <input type="submit" value="submit it"/>
        </form>
        </body></html>"""



if __name__ == "__main__":
    app.debug = True
    app.run()

如何将这两个python文件相互通信? 谢谢!

0 个答案:

没有答案