jinja2.exceptions.TemplateNotFound: bootstrap/base.html
新人在学flaskweb
在进入index.html时候出错为jinja2.exceptions.TemplateSyntaxError: unexpected '%'
在进入user.html页面和404.html页出现jinja2.exceptions.TemplateNotFound: bootstrap/base.html
求解答?
下面是python,文件
!/usr/bin/env python
-- coding: utf-8 --
@Time : 2017/10/12 16:58
@Author :
@Site :
@File : hello.py
@Software: PyCharm Community Edition
from flask import Flask,render_template
from flask_script import Manager
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import Form
from wtforms import StringField,SubmitField
from wtforms.validators import Required
app=Flask(__name__)
manager=Manager(app)
bootstrap=Bootstrap(app)
moment=Moment(app)
app=Flask(__name__)
app.config['SECRET_KEY']='hard to guess string'
表单
class NameForm(Form):
name=StringField('What is your name?',validators=[Required()])
submit=SubmitField('submit')
@app.route('/',methods=['GET','POST'])
def index():
name=None
form=NameForm()
if form.validate_on_submit():
name=form.name.data
form.name.data=''
return render_template('index.html',form=form,name=name)
@app.route('/user/<name>')
def user(name):
return render_template('user.html',name=name)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'),404
@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'),500
if __name__=='__main__':
app.run(debug=True)
# manager.run()
下面是模板代码
模板base.htm
{% extends "bootstrap/base.html" %}
{% block title %}Flasky{% endblock %}
{%block head%}
{{super()}}
<link rel="shortcut icon" href="{{url_for('static',filename='favicon.ico')}}"
type="image/x-icon">
<link rel="icon" href="{{url_for('static',filename='favicon.ico')}}"
type="image/x-icon">
{% endblock %}
{%block scripts%}
{{super()}}
{{moment.include_moment()}}
{%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">
{% block page_content %}
{% endblock%}
</div>
{% endblock%}
index.html模板
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Flasky{% endblock %}
{%block page_content%}
<div class="page-content">
<h1>Hello,{%if name%}{{name}}{{%else%}}Stringer{%endif%}!</h1>
</div>
{{wtf.quick_form(form)}}
{%endblock%}
user.htm 模板
{% extends "base.html" %}
{% block title %}Flasky{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Hello,{{name}}!</h1>
</div>
{% endblock%}
404.html模板
{% extends "base.html"%}
{%block title%}Flask-Page Not Found{%endblock%}
{% block page_content %}
<div class="page_header">
<h1>Not Found</h1>
</div>
{% endblock%}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论