Python 烧瓶和Jinja2模板模板模板第1行的合成错误
我正在尝试使用Flask创建一个示例应用程序。一切正常,但问题不知从何而来 我的回溯和源文件附在这篇文章中。我想提及的是,我已经尝试更改行结束格式(类似UNIX、Windows)和编码(ANSI、UTF-8、UTF-8 w/o BOM) 这是我的runserver.py:Python 烧瓶和Jinja2模板模板模板第1行的合成错误,python,flask,jinja2,Python,Flask,Jinja2,我正在尝试使用Flask创建一个示例应用程序。一切正常,但问题不知从何而来 我的回溯和源文件附在这篇文章中。我想提及的是,我已经尝试更改行结束格式(类似UNIX、Windows)和编码(ANSI、UTF-8、UTF-8 w/o BOM) 这是我的runserver.py: # -*- coding: utf-8 -*- import os from flask import Flask, render_template, send_from_directory, url_for # initi
# -*- coding: utf-8 -*-
import os
from flask import Flask, render_template, send_from_directory, url_for
# initialization
app = Flask(__name__)
app.config.update(
DEBUG = True,
)
# controllers
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'ico/favicon.ico')
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.route("/")
def index():
return render_template('index.html')
@app.route("/base")
def base():
return render_template('base.html')
# launch
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
以下是我的模板:
base.html
{%block head%}
{# #}
{%block title%}{%endblock%}-我的网页
{%endblock%}
{%block content%}{%endblock%}
{%block footer%}
&抄袭;版权所有2010年。
{%endblock%}
和index.html
{%extends“base.html”%}
{%block title%}-Home{%endblock%}
{%block content%}
{%if-not session.logged_in%}
您没有登录
{%else%}
您已登录
{%endif%}
{%endblock%}
这是什么确切的Python 2.7版本?你能打开Python并尝试一下''。解码('unicode-escape')
?这是否也引发了一个异常?您使用了哪个程序创建模板?@MartijnPieters,Python 2.7.8>>''。解码(“unicode-escape”)回溯(最近一次调用):文件“”,第1行,在LookupError:unknown encoding:unicode escape>>>@Burnkhalid,我尝试了升华文本和记事本++。@NobodyOne:right,unicode转义编码是基本的,如果没有,我会说你的Python安装坏了。
# -*- coding: utf-8 -*-
import os
from flask import Flask, render_template, send_from_directory, url_for
# initialization
app = Flask(__name__)
app.config.update(
DEBUG = True,
)
# controllers
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'ico/favicon.ico')
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.route("/")
def index():
return render_template('index.html')
@app.route("/base")
def base():
return render_template('base.html')
# launch
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)