当我运行此示例代码时:
void func(int x)
{
std::cout<<x<< " I'm a free func!\n";
}
class Obj
{
public:
void member(int x) { std::cout<<x<< " I'm a member func!\n";}
};
int main()
{
// Define the signature
using func_ref_t = function_ref<void(int)>;
// Can be used with stateful lambdas
int bar = 1;
auto lambda = [&bar](int x){std::cout<<x<< " I'm a lambda!\n"; ++bar;};
// Copy and move
func_ref_t lref(lambda);
auto cpy = lref;
auto mv = std::move(lref);
cpy(1);
mv(2);
// See the modified var from the lambda
std::cout<<bar<<'\n';
// Use with free functions
auto fref = func_ref_t{func};
fref(4);
// We can wrap member functions with stateful lamdas
Obj obj;
auto mem = [&obj](int x) { obj.member(x); };
auto mref = func_ref_t{mem};
mref(5);
}
在终端上输入以下内容:from flask import Flask
app = Flask(__name__)
def main () :
return "Welcome to Flask "
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=80)
,输出为:
python3 app.py
它不会停止
当我在浏览器中打开127.0.0.1时,它会显示 * Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production
environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 144-032-769
127.0.0.1 - - [13/Jun/2018 00:11:59] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Jun/2018 00:11:59] "GET /favicon.ico HTTP/1.1" 404
-
127.0.0.1 - - [13/Jun/2018 00:12:15] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Jun/2018 00:12:16] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [13/Jun/2018 00:12:22] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Jun/2018 00:12:22] "GET /favicon.ico HTTP/1.1" 404 -
答案 0 :(得分:2)
你没有给main()
路线装饰者。你的功能应该是这样的:
@app.route('/')
def main():
return "Welcome to Flask "