烧瓶-render_template无法呈现html页面

时间:2019-12-25 17:56:07

标签: python flask

我需要以下代码的帮助。

root@ip-xxxxxxxx:~/flaskapp# cat flaskapp.py
from flask import Flask, render_template, redirect, url_for, request
app = Flask(__name__)

@app.route('/hello')
def hello_world():
    return render_template('testing.html', name = 'john')
    if __name__ == '__main__':
   app.run()
root@ip-xxxxxxx:~/flaskapp#

当我打开站点(http://www.example.com/hello)时,页面返回500 Internal Server Error。 有人可以协助解决代码错误吗?  上面的文件(flaskapp.py)在html根目录下的flask flask文件夹下。还将test.html放在flaskapp文件夹内的templates文件夹下。

下面是/etc/apache2/sites-enabled/000-default.conf文件的内容

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>

以下是apache错误日志

文件“ /var/www/html/flaskapp/flaskapp.py”,第8行     app.run()       ^ IndentationError:预期出现缩进的块

1 个答案:

答案 0 :(得分:2)

File "/var/www/html/flaskapp/flaskapp.py", line 8 app.run() ^ IndentationError: expected an indented block

Apache告诉您,由于缩进问题,flaskapp.py中的第8行出现错误。 Python is very sensitive with regards to indentation.您具有:

    if __name__ == '__main__':
   app.run()

希望这会有所帮助!

app.run()应该进一步缩进,以使其似乎在if语句的“下方”。尝试将代码更改为如下所示,看看是否可以解决该问题:

    if __name__ == '__main__':
        app.run()