Flask AttributeError: 'function' object has no attribute 'run' - Solution and Explanation
This error occurs when you try to call the 'run()' method on a function object instead of an instance of the Flask application.
To fix this error, make sure you create an instance of the Flask application before calling the 'run()' method. Here's an example:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
In this example, we create an instance of the Flask application using Flask(__name__) and assign it to the app variable. Then, we define a route and a corresponding view function using the @app.route() decorator. Finally, we call the 'run()' method on the app instance to start the Flask development server.
Make sure to replace app.py with the correct file path and modify the route and view function according to your application's needs.
原文地址: https://www.cveoy.top/t/topic/kf9V 著作权归作者所有。请勿转载和采集!