Giter VIP home page Giter VIP logo

Comments (4)

IvanLjubicic avatar IvanLjubicic commented on May 23, 2024

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.

wadi-it-bc avatar wadi-it-bc commented on May 23, 2024

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__)
  • remove (or rename) app.py: you won't be using it anymore
  • edit mail_services.py: in stead of from app import app use from 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'
  • run the app: python flasky.py (or in this case something like python movie-bag.py or python 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)

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.

chuck-tz avatar chuck-tz commented on May 23, 2024

@wadi-it-bc Could you please explain a bit what the two-sided double asterisks current_app do?

from flask-rest-api-blog-series.

wadi-it-bc avatar wadi-it-bc commented on May 23, 2024

@chuck-tz Argh, I made a typo, sorry!
I removed the asterisks 😳

from flask-rest-api-blog-series.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.