heroking146 发表于 2020-10-27 09:32:13

python3.85 已下载手动安装Fask

from flask importFlask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'hello World'


if __name__ == '__main__':
    app.run()

导包也显示成功未出现错误,可是一运行就出现下面错误,不知何故?????

ImportError: cannot import name 'Flask' from partially initialized module 'flask' (most likely due to a circular import) (E:\python代码\python听课练习\爬虫\flask.py)

hrp 发表于 2020-10-27 09:35:34

你自己的py文件不要用flask.py做文件名,这样会导致从你自己的flask文件导入,当然会出错了。

heroking146 发表于 2020-10-27 10:27:20

hrp 发表于 2020-10-27 09:35
你自己的py文件不要用flask.py做文件名,这样会导致从你自己的flask文件导入,当然会出错了。

谢谢修改了,以前的问题解决了。新的问题又来了。执行后打开网页是下边的情况了..这是什么原因呢????I


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.

heroking146 发表于 2020-10-27 10:29:17

from flask import Flask
from jinja2 import Markup, Environment, FileSystemLoader
from pyecharts.globals import CurrentConfig

# 关于 CurrentConfig,可参考 [基本使用-全局变量]
CurrentConfig.GLOBAL_ENV = Environment(loader=FileSystemLoader("./templates"))

from pyecharts import options as opts
from pyecharts.charts import Bar


app = Flask(__name__, static_folder="templates")


def bar_base() -> Bar:
    c = (
      Bar()
      .add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
      .add_yaxis("商家A", )
      .add_yaxis("商家B", )
      .set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))
    )
    return c


@app.route("/")
def index():
    c = bar_base()
    return Markup(c.render_embed())


if __name__ == "__main__":
    app.run()


这是代码,所有导包都正常。
执行就出现下边错误了
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.
页: [1]
查看完整版本: python3.85 已下载手动安装Fask