Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal server error Flask

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
like image 462
Liondancer Avatar asked Jun 17 '14 02:06

Liondancer


People also ask

How do I fix an internal server error on a Flask?

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.

How do I fix error 404 in Flask?

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.

What is status 500 internal server error?

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 internal server error?

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.


2 Answers

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.

like image 70
Hiro Avatar answered Oct 18 '22 18:10

Hiro


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
like image 21
Leonardo.Z Avatar answered Oct 18 '22 20:10

Leonardo.Z