-1
這不是重複的問題。我已經更新了類似問題中的答案,但它仍然無法正常工作。我對燒瓶,html和python很新,所以我確實需要幫助。我可能在某處看到了我的回答,但沒有認出它。在燒瓶中渲染模板時發生HTTP 500錯誤
下面的代碼不會呈現index.html模板。相反,我得到一個HTTP 500錯誤(jinja2.exceptions.TemplateSyntaxError:expected token',','string')。我認爲問題出在.html文件中,因爲當我在不更改我的app.py代碼的情況下呈現其他index.html模板時,將呈現html模板。
下面是app.py
from flask import Flask, render_template, request, session, abort
app = Flask(__name__)
app.static_folder = 'static'
@app.route('/', methods=['GET'])
def test():
resp = make_response(render_template('index.html'))
return resp
@app.route('/getTenants', methods=['GET'])
def dummy():
data = ['Black', 'Blue', 'White', 'Pink']
return jsonify(results=data)
if __name__ == "__main__":
app.run(debug=True)
代碼下面是index.html中的代碼
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' />
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.ico') }}">
<title>Create Contract</title>
<!-- CSS -->
<link href="{{ url_for('static', filename= 'css/common.min.css') }}" rel="stylesheet" />
<link href="{{ url_for('static', filename= 'css/simple-line-icons.css') }}" rel="stylesheet" />
<link href="{{ url_for('static', filename= 'css/style.css') }}" rel="stylesheet" />
<head>
<body>
<!-- Spinner -->
<div class="spinner global" ng-class="{'showing' : loading }"><div class="spinner-icon"></div></div>
<!-- Main View -->
<div ui-view></div>
<!-- Awesome Angular -->
<script src="{{ url_for('static', filename='js/libs/angular.min.js') }}"></script>
<!-- AngularJS plugins -->
<script src="{{ url_for('static', filename='js/libs/ui-bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/angular-ui-router.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/ocLazyLoad.min.js') }}"></script>
<script src="{{ url_for('static', filename=js/libs/loading-bar.min.js') }}"></script>
<!-- App scripts -->
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
<script src="{{ url_for('static', filename='js/routes.js') }}"></script>
<script src="{{ url_for('static', filename='js/services.js') }}"></script>
<script src="{{ url_for('static', filename='js/controllers.js') }}"></script>
<script src="{{ url_for('static', filename='js/directives.js') }}"></script>
</body>
</html>
回溯錯誤 jinja2.exceptions.TemplateSyntaxError: expected token ',', got 'string'
可有人請讓我知道我做錯了嗎?
有太多的代碼在這裏。請儘量減少模板以顯示問題。 –
我已經將模板減少到最小 – DeeChok
削減了幫助你理解它嗎? – DeeChok