《Flask Web开发实例3-5为何总报错
我阅读了《Flask Web开发》 实例3-5疑问,并将其代码复制到自己的电脑上,但是还是报错。
user.html
{% extends "bootstrap/base.html" %}{% block title %}Flasky{% endblock %}
{% block navbar %}
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle"
data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Flasky</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
</ul>
</div>
</div>
</div>
{% endblock %}
{% block content %}
<div class="container">
<div class="page-header">
<h1>Hello,{{ name }}!</h1>
</div>
</div>
{% endblock %}
index.html
<h1>Hello World!</h1>
base.html
<html><head>
{% block head %}
<title>{% block title %}{% endblock %} - My Application</title>
{% endblock %}
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
Hello.py
from flask_bootstrap import Bootstrapfrom flask_script import Manager
from flask import Flask
from flask import render_template
app = Flask(__name__)
bootstrap = Bootstrap(app)
manager = Manager(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
return render_template('user.html', name=name)
if __name__ == '__main__':
manager.run()
但是运行出来却是这个样子:
想问问为什么
回答:
我已经解决了这个问题,原因是我的hello.py和templates文件夹没有处在同一级目录中
以上是 《Flask Web开发实例3-5为何总报错 的全部内容, 来源链接: utcz.com/a/159314.html