python decorator in flask

Viewed 2022

Here is my example:

from flask import Flask

app = Flask(__name__)
def add1(f):
    def inner(*args, **kwargs):
        return str(f(*args, **kwargs))+'1'
    return inner


@app.route('/')
@add1
def hello1():
    return "hello1";

@app.route('/hello2')
@add1
def hello2():
    return "hello2";


if(__name__ =='__main__'):
    app.run()

When I run 127.0.0.1:5000, I expect to get "hello11", but I get "hello21", why?

1 Answers
Related