瓶子 - render_template 不渲染html页

2024-03-28 20:54:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要以下代码的帮助

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个内部服务器错误。 有人能帮我找出密码有什么问题吗? 上面的文件(flaskapp.py)位于html根目录下的文件夹flaskapp下。testing.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:应为缩进块


Tags: 文件namefrompyip文件夹appflask
1条回答
网友
1楼 · 发布于 2024-03-28 20:54:18

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()

相关问题 更多 >