Usi Usi
Usi Usi

Reputation: 2997

Heroku Python Flask serves index.html page

Flask can't serve an index.html page... it seems that it doesn't recognize the static folder

enter image description here

It serves the index.html in this way

from flask import Flask, request, render_template, url_for, redirect


# set the project root directory as the static folder, you can set others.
app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def root():
    if request.method == 'GET':
        return redirect(url_for('static', filename='index.html'))
    if request.method == 'POST':

But I receive an Internal Server Error

Upvotes: 0

Views: 424

Answers (1)

Simon Melouah
Simon Melouah

Reputation: 652

This could be a stupid suggestion but maybe try renaming the directory to 'templates' and use the render_template function. From my experience I've only ever used redirect(url_for()) to point to a different function in Python i.e.

@app.route('/', methods=['GET', 'POST'])
def root():
    if request.method == 'GET':

        return render_template('index.html')


    if request.method == 'POST':

        return redirect(url_for('another_function'))

@app.route('/another_route', methods=['GET'])
def another_function():
       if request.method == 'GET':
         ....

Upvotes: 1

Related Questions