Reputation: 21
I need help on the below code.
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#
When I am opening my site (http://www.example.com/hello), the page is returning 500 Internal Server Error. Can someone be able to assist whats wrong with the code ? The above file (flaskapp.py) is under folder flaskapp which is under the html root directory. Also the testing.html is placed under the templates folder inside the flaskapp folder.
Below is the content of /etc/apache2/sites-enabled/000-default.conf file
<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>
below is the apache error log
File "/var/www/html/flaskapp/flaskapp.py", line 8 app.run() ^ IndentationError: expected an indented block
Upvotes: 0
Views: 137
Reputation: 187
File "/var/www/html/flaskapp/flaskapp.py", line 8 app.run() ^ IndentationError: expected an indented block
Apache is telling you that there was an error reading line 8 in flaskapp.py
because of indentation issues. Python is very sensitive with regards to indentation. You have:
if __name__ == '__main__':
app.run()
Hope this helps!
app.run()
should be indented further so that it appears to be "under" the if statement. Try changing your code to look like the following and see if this fixes it:
if __name__ == '__main__':
app.run()
Upvotes: 2