Hier ist mein Projekt-Layout:'Funktion' Objekt hat kein Attribut 'name', wenn Entwurf Registrierung
baseflask/
baseflask/
__init__.py
views.py
resources/
health.py/
wsgi.py/
Hier ist mein Druck
from flask import Blueprint
from flask import Response
health = Blueprint('health', __name__)
@health.route("/health", methods=["GET"])
def health():
jd = {'status': 'OK'}
data = json.dumps(jd)
resp = Response(data, status=200, mimetype='application/json')
return resp
Wie ich in __init__.py
registrieren:
import os
basedir = os.path.abspath(os.path.dirname(__file__))
from flask import Blueprint
from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
app.debug = True
CORS(app)
from baseflask.health import health
app.register_blueprint(health)
Hier ist der Fehler:
Traceback (most recent call last):
File "/home/ubuntu/workspace/baseflask/wsgi.py", line 10, in <module>
from baseflask import app
File "/home/ubuntu/workspace/baseflask/baseflask/__init__.py", line 18, in <module>
app.register_blueprint(health)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 880, in register_blueprint
if blueprint.name in self.blueprints:
AttributeError: 'function' object has no attribute 'name'
Beachten Sie, dass der Fehler, den Sie gemacht haben, nicht spezifisch für Flask oder seine Blaupausen ist. Wenn Sie jedoch der Meinung sind, dass die Dokumentation verbessert werden muss, sollten Sie auf jeden Fall konstruktiv mit dem Projekt über die [Issues-Seite] des Projekts (https://github.com/pallets/flask/issues) Kontakt aufnehmen. – jonrsharpe