如何在python中读取站点url /参数

时间:2013-01-15 10:25:45

标签: python flask

好的,我有一个python应用程序说例如www.example.com。假设我点击了一个类似www.exmaple.com/function1的网址,那么是否可以在python应用程序中读取function1

这是我的python代码

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')

def hello():
    return 'Hello World --  jay!'

@app.route('/fun')
def fun():
    return 'have func!'

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

1 个答案:

答案 0 :(得分:0)

试试这个:

@app.route('/<func>')
def fun(func):
    return 'have func :' + func + "!"