Flask应用程序在运行Python35后未提供输出

时间:2018-07-23 12:47:09

标签: python python-3.x flask

这是我要运行的应用程序代码:

from flask import Flask, request, render_template
import json
import requests
import socket
from datetime import datetime
import pickle
import time
import pandas as pd
import numpy as np
@app.route('/index.html')
def index():
    return render_template('index.html')

@app.route('/tables.html')
def tables():
    return render_template('tables.html')

@app.route('/flot.html')
def flot():
    return render_template('flot.html')

@app.route('/morris.html')
def morris():
    return render_template('morris.html')

@app.route('/forms.html')
def forms():
    return render_template('forms.html')

@app.route('/panels-wells.html')
def panelswells():
    return render_template('panels-wells.html')

@app.route('/buttons.html')
def buttons():
    return render_template('buttons.html')

@app.route('/notifications.html')
def notifications():
    return render_template('notifications.html')

@app.route('/typography.html')
def typography():
    return render_template('typography.html')

@app.route('/icons.html')
def icons():
    return render_template('icons.html')

@app.route('/blank.html')
def blank():
    return render_template('blank.html')


@app.route('/login.html')
def login():
    return render_template('login.html')

if __name__ == '__main__':

    app.run(host='0.0.0.0', port=8080, debug=True, threaded=True)
    pass

这是我的运行方式:

C:\Users\aims\Desktop\forex>python forex_app.py
 * Serving Flask app "forex_app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 122-288-656
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
 * Detected change in 'C:\\Users\\aims\\Desktop\\forex\\forex_app.py', reloading
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 122-288-656

在以http://0.0.0.0:8080甚至http://0.0.0.0:8080/index.html的形式访问网址后,我看到以下屏幕:
output image

请帮助我所缺少的。我有html文件夹中的templates模板。查看图片:
folder images

请让我知道。

2 个答案:

答案 0 :(得分:1)

这里有很多错误。

0.0.0.0不是您放入浏览器的地址;告诉服务器绑定到任何地址是一个特殊的值。您需要通过本地IP(127.0.0.1:8080)访问站点。

第二,您没有在Flask代码中为根路径定义路由处理程序;您只定义“ index.html”,依此类推。我怀疑您误解了那里发生的一切;该路线是您放入浏览器中的路线,与您呈现的模板没有任何关系。为/定义一条路由是完全可能的(并且更可取的),但是处理程序可以渲染“ index.html”:

@app.route('/')
def index():
    return render_template('index.html')

答案 1 :(得分:1)

尝试127.0.0.1:8080,0.0.0.0:8080仅表示该应用正在侦听所有连接