Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶渲染“U模板()返回”;名称错误:名称';app&x27;“未定义”;_Python_Flask - Fatal编程技术网

Python 烧瓶渲染“U模板()返回”;名称错误:名称';app&x27;“未定义”;

Python 烧瓶渲染“U模板()返回”;名称错误:名称';app&x27;“未定义”;,python,flask,Python,Flask,我正在遵循烧瓶的快速入门指南。 我在遵循指南时遇到了这个错误 /application /__init__.py /templates /hello.html @app.route('/hello/') @app.route('/hello/<name>') def hello(name=None): return render_template('hello.html', name=name) >python _init_.

我正在遵循烧瓶的快速入门指南。 我在遵循指南时遇到了这个错误

/application
/__init__.py
/templates
    /hello.html

   @app.route('/hello/')
   @app.route('/hello/<name>')
   def hello(name=None):
       return render_template('hello.html', name=name)

    >python _init_.py 
        Traceback (most recent call last):
        File "_init_.py", line 4, in <module>
   @app.route('/hello/')
   NameError: name 'app' is not defined
/应用程序
/__初始值
/模板
/hello.html
@app.route(“/hello/”)
@app.route(“/hello/”)
def hello(name=None):
返回呈现模板('hello.html',name=name)
>python_init_u2;.py
回溯(最近一次呼叫最后一次):
文件“\u init\u.py”,第4行,在
@app.route(“/hello/”)
NameError:未定义名称“app”

查看上的最小程序,尤其是前两行:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
您的问题是您没有烧瓶模块,也没有初始化烧瓶模块。

您需要:

from flask import request
我认为这是Flask的快速入门指南中的一个缺陷。

也许是这个


从烧瓶导入烧瓶、请求、渲染模板

唯一缺少的是

from flask import Flask, render_template

我很惊讶没有人在回答这个问题时做标记。正如许多人所建议的,我还可以从flask import flask确认
,render_template
解决了问题

您只需要导入render_模板<代码>从烧瓶导入烧瓶,渲染模板发现问题。。。。。。。。在代码中,变量name和main有2个下划线。。我用了一个。