Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 flask issues with app structuring
#1
Hi all,

I am new to this forum. I recently started working on my first flask application. I am having some issues with imports in my project. My project structure is as follows:

<project>
│ amazon_scraper_app.db
│ README.md
│ run_server.py
│ server_deprecated.py
│ __init__.py


├───amazon_scraper_app
│ │ additional_routes.py
│ │ api_resource_models.py
│ │ customExceptions.py
│ │ database_models.py
│ │ database_utilities.py
│ │ models.py
│ │ server.py
│ │ server_utilities.py
│ │ test.db
│ │ __init__.py


├───config
│ │ config.py
│ │ settings.py


I have my class in the amazon_scraper_app.__init__ module. I initialize an object of my class and import that object to all other files such as amazon_scraper_app.database_utilities etc.. I am importng the my_app object from amazon_scraper_app.__init__ to amazon_scraper_app.database_utilities to access the 'db' of the flask app which is just SQLAlchemy(flask_app). I am also importing methods from amazon_scraper_app.database_utilities to amazon_scraper_app.api_resource_models. The classes in amazon_scraper_app.api_resource_models are imported in amazon_scraper_app.__init__ to serve as REST API handlers to the flask server. This causes some kind of loop of imports and I am stuck with an error like this:

C:\Users\siddh\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/siddh/Documents/Python/amazon-scraper/run_server.py
Traceback (most recent call last):
File "C:/Users/siddh/Documents/Python/amazon-scraper/run_server.py", line 1, in <module>
from amazon_scraper_app import my_app
File "C:\Users\siddh\Documents\Python\amazon-scraper\amazon_scraper_app\__init__.py", line 5, in <module>
from amazon_scraper_app.api_resource_models import AmazonProductListResource, AmazonProductResource, \
File "C:\Users\siddh\Documents\Python\amazon-scraper\amazon_scraper_app\api_resource_models.py", line 3, in <module>
from amazon_scraper_app.database_utilities import get_products
File "C:\Users\siddh\Documents\Python\amazon-scraper\amazon_scraper_app\database_utilities.py", line 1, in <module>
from amazon_scraper_app.database_models import AmazonProduct, db, AmazonProductPrice
File "C:\Users\siddh\Documents\Python\amazon-scraper\amazon_scraper_app\database_models.py", line 1, in <module>
from amazon_scraper_app import my_app
ImportError: cannot import name 'my_app' from 'amazon_scraper_app' (C:\Users\siddh\Documents\Python\amazon-scraper\amazon_scraper_app\__init__.py)

Please help as I am out of ideas on how I can resolve this. I am very new this.

Thanks!

Sid
Quote
#2
see: https://blog.miguelgrinberg.com/post/the...-structure
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  python 3.7 on windows using flask and flask-sqlalchemy. Alpy 2 1,515 Aug-12-2020, 07:24 PM
Last Post: Alpy
  Flask Issues iainstott 12 9,744 Oct-29-2016, 06:07 PM
Last Post: iainstott

Forum Jump:


Users browsing this thread: 1 Guest(s)