Heroku Python Flask提供index.html页面

时间:2015-09-07 01:01:33

标签: python heroku flask

Flask无法提供index.html页面......似乎它无法识别静态文件夹

enter image description here

它以这种方式提供index.html

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':

但是我收到内部服务器错误

1 个答案:

答案 0 :(得分:1)

这可能是一个愚蠢的建议,但可能会尝试将目录重命名为' templates'并使用render_template函数。根据我的经验,我只使用重定向(url_for())指向Python中的不同函数,即

@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':
         ....