First time learning Flask and I am trying to build things following a tutorial. I am getting this message in my browser when I input this url:
http://127.0.0.1:5000/index
127.0.0.1 - - [16/Jun/2014 19:37:41] "GET /index HTTP/1.1" 500 -
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
I'm not sure why I am getting this error. Could someone help me out and tell me why? I am new to Flask and web development
code:
from flask import Flask, request, make_response, redirect, render_template
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap
app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
return render_template('user.html', name = name)
if __name__ == '__main__':
#app.run(debug = True)
manager.run()
index.html:
{% extends "base.html" %}
{% block title %} Index {% block title %}
{% block head %}
<!-- Uses super() to retain the original contents-->
{{ super() }}
<style type="text/css">
</style>
{% endblock %}
{% block body %}
<h1>Hello, World!</h1>
{% endblock %}
This is my project structure:
/Flask_0_11
/templates
base.html
index.html
user.html
hello.py
Step 1 — Using The Flask Debugger. In this step, you'll create an application that has a few errors and run it without debug mode to see how the application responds. Then you'll run it with debug mode on and use the debugger to troubleshoot application errors.
For this, we need to download and import flask. Download the flask through the following commands on CMD. Using app.py as our Python file to manage templates, 404. html be the file we will return in the case of a 404 error and header.
The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This error response is a generic "catch-all" response.
What causes a 500 Internal Server error. This error means there is a problem on the server side. A server error can be caused by any number of things from uploading the incorrect file to as bug in a piece of code. This error response is a generic "catch-all" response.
First of all try to run the app using
python manage.py runserver -d
This will run your flask app in debug mode showing the errors encountered in your app making correction easily.
Secondly,there may be error due to no WTF_CSRF_ENABLED = True with SECRET_KEY in your config file.
There's a template syntax error in your index.html
.
The title block should be closed with {% endblock %}
:
{% block title %} Index {% endblock %}
You can turn on the DEBUG
configuration for debugging. Because you use Flask-Script
, you can pass the -d
option to the runserver command.
e.g.
python hello.py runserver -d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With