欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

<>hello.py遇见的几个坑

程序员文章站 2022-07-12 16:03:32
...

在看<<flask web开发>>文章中第16页,在做示例2-3时,

from flask import Flask
app = Flask(__name__)
from flask.ext.script import Manager
manager = Manager(app)

@app.route('/user/<name>')
def user(name):
    return '<h1>Hello, %s!</h1>' % name

if __name__=='__main__':
    manager.run()
在运行时报以下错误:

E:\Python36>python hello.py
hello.py:42: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
  from flask.ext.script import Manager
usage: hello.py [-?] {shell,runserver} ...

positional arguments:
  {shell,runserver}
    shell            Runs a Python shell inside Flask application context.
    runserver        Runs the Flask development server i.e. app.run()

optional arguments:
  -?, --help         show this help message and exit

 

这里面告诉了我们两条有用的信息,第一条就是,我们应该导入from flask_script import Manager

第二条就是运行的时候,我们应该写成E:\Python36>python hello.py runserver

 

最后完美解决!