Comments (4)
I believe it is a circular dependency issue.
like in this one
https://stackoverflow.com/questions/17845366/importerror-cannot-import-name/17845428
I am dealing with it now.
from flask-rest-api-blog-series.
The probable workaround, I'm not very good at describing the solution, but I'll try:
Implement most of the app structure as done in https://github.com/miguelgrinberg/flasky
So we're trying to avoid the circular reference by:
- creating a new set up for the flask app
- app.py won't be used any more
- we'll implement create_app() as a function to define the app
- creating a new start up file to actually run the app by calling the create_app function
Steps:
- create and use
__init__.py
in your movie-bag folder to set up the flask app- move the code in app.py to
__init__.py
(double underscores before and after) - also use the create_app set up as shown in the flasky project, but without the additional parameters, just use
def create_app():
app = Flask(__name__)
- move the code in app.py to
- remove (or rename) app.py: you won't be using it anymore
- edit mail_services.py: in stead of
from app import app
usefrom movie-bag import current_app
- you probably have to set FLASK_APP environment variable to 'movie-bag.py' for flask to get hold of the current_app as defined in
__init__.py
- linux:
export $FLASK_APP='movie-bag.py'
- windows (I think):
SET FLASK_APP='movie-bag.py'
- linux:
- run the app:
python flasky.py
(or in this case something likepython movie-bag.py
orpython run.py
)- this will include the actual call to the create_app in the previously created
__init__.py
- this file will be placed outside the movie-bag folder (1 level higher)
- this will include the actual call to the create_app in the previously created
Don't get distracted by other code in this flasky project (although it's a great project to learn from), focus on getting the same structure.
This worked for me.
Good luck.
from flask-rest-api-blog-series.
@wadi-it-bc Could you please explain a bit what the two-sided double asterisks current_app do?
from flask-rest-api-blog-series.
@chuck-tz Argh, I made a typo, sorry!
I removed the asterisks 😳
from flask-rest-api-blog-series.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-rest-api-blog-series.