![]() # Other flask extensions you might use also import hereĪnd then, in any other module, you will import a particular extension from extensions.py instead of app.py, and then you will evade circular imports. What works for me and I think is an acceptable and clean solution is defining your app structure something like this: your_project/Įxtensions.py should look something like this: from flask_sqlalchemy import SQLAlchemy So the most straightforward explanation is this:Īs you can see from this example, both modules import one another, and that causes circular imports that are a common problem when learning flask. They usually require restructuring your code. I've tried putting the function on a module but I still need to import the db from the main file and cause a circular import error againĬircular imports can be painful. How am I supposed to "bypass" that error. ImportError: cannot import name 'admin' from partially initialized module 'blueprints.admin' (most likely due to a circular import) Return render_template('books.html',action = action, books = books) Now I'm trying to use the function in the blueprints from app import getdata I made a simple function to get the book list from the DB books = (Book).all() as the db is declared in the main file. both are supposed to get access to view the books available. ![]() I have 2 blueprints, one for an admin and one for a simple user. I'm building a basic "library" as a first project with flask and sqlalchemy OpenShift (requires extensive ssh installation of ruby, python, etc.). ![]() Google App Engine (Desktop admin app flask can be configured with this repo).WebFaction (SSH paid-web-host flask must be installed by you possible configuration and path issues possible SFTP).Heroku (SSH flask must be installed by you, slightly-difficult-windows-instructions, upgradeable cloud service).(web-SSH web-instant-MySQL-db web-IDE instant deployment of flask, free easy logs github/single-file-upload support SFTP/SSH requires pay).Official Flask website and documentation.Use if you are discussing a certain extension to Flask.Īlso check out /r/python or /r/django Websites built with Flask Use or if you have a very specific problem and need help with code. Use Python and Flask to build the web faster
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |