1

I'm trying create custom flask extension and use it within my application. I'm using below project structure.

ExapmpleProject
--> apps
--> extensions
   -->flask-customext
      -->__init__.py
      -->flask_customext.py
      -->setup.py
--> sample.py

sample.py

from flask import Flask
from flask.ext import customext
app = Flask(__name__)


@app.route('/')
def hello_world():
    if customext.validate():
        return 'Hello World!'
    else:
        return 'not allowed!'



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

I followed standard class based extension within flask-customext package as defined in the extention dev doc. How can I install this customext to be imported by from flask.ext import customext used in sample.py as any other flask-extensions does.

Not sure if this do the job but I tried python setup.py install. but it raised below error

error: package directory 'flask_customext' does not exist
4

1 回答 1

0

文件说_

扩展都位于一个名为 flask_something 的包中

而在您的示例中,包名为flask-customext,因此它应该是flask_customext。

此外,在扩展导入转换章节中,建议使用新的导入约定:

import flask_something

代替:

import flask.ext.something
于 2017-04-03T08:23:40.617 回答