【发布时间】:2019-12-25 17:56:07
【问题描述】:
我需要以下代码的帮助。
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 根目录下的文件夹 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 行 应用程序运行() ^ IndentationError: 需要一个缩进块
【问题讨论】:
-
我认为你需要检查 Apache 错误日志
-
烧瓶日志说什么?
-
@CrazyElf - 使用 apache 错误日志编辑了代码
-
if __name__ == "__main__"块在hello_world()函数定义下缩进。不应该。 -
@CrazyElf & marxmacher - 非常感谢大家的帮助。我检查了 apache 错误日志,发现这是一个缩进相关的问题。我已经修复它并且代码按预期工作