Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have
autocomplete
function as a separate file - autocomplete.py. The autocomplete is being imported into
.py as follows:
from xyzapp.autocomplete import autocomplete
The line that throws error in autocomplete.py is the following:
@app.route('/autocomplete',methods=['GET'])
The structure of the application is using blueprints and looks as follows:
appcontainer
|--run.py
|--xyzapp
|--__init__.py
|--autocomplete.py
|--blueprint_folder_1
|--blueprint_folder_2
|--static
The whole error message looks like this:
@app.route('/autocomplete',methods=['GET'])
AttributeError: module 'flask.app' has no attribute 'route'
Any ideas what I am doing wrong?
UPDATE:
The autocomplete.py looks as follows:
from flask import Flask, render_template, redirect, url_for, request, session, flash, app, Blueprint, jsonify
@app.route('/autocomplete',methods=['GET'])
def autocomplete():
database='backbone_test'
db=client[database]
all_names=list(db.ids.find({},{"current_name":1,"_id":0}))
return json.dumps(all_names)
The __init__.py
file looks as follows:
from flask import Flask, render_template, Blueprint, jsonify, session
import jinja2
class MyApp(Flask):
def __init__(self):
Flask.__init__(self, __name__)
self.jinja_loader = jinja2.ChoiceLoader([self.jinja_loader,jinja2.PrefixLoader({}, delimiter = ".")])
def create_global_jinja_loader(self):
return self.jinja_loader
def register_blueprint(self, bp):
Flask.register_blueprint(self, bp)
self.jinja_loader.loaders[1].mapping[bp.name] = bp.jinja_loader
app = MyApp()
from xyzapp.autocomplete import autocomplete
from xyzapp.blueprint_folder_1.some_file import bp_1
app.register_blueprint(bp_1)
–
–
–
I'm sorry this is a bit of a long shot, I'm not familiar with this way of running a Flask app, but it seems you create your own instance of the Flask class called MyApp and initialise it under the variable app.
I'm not 100% and may be completely wrong, but I think your problem lies in the __init__
of MyApp
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
烦恼的日记本
Getting Missing IN or OUT parameter at index :: 1 Vendor code 17041 error - Oracle Forums
挂过科的甜瓜
解决DevTools failed to load SourceMap: Could not load content for ***.js.map: HTTP error: code 404 问题_
31 分钟前