hello everyone :) noob here,
I had a question about how objects can be called from a package.
I have been following along with this tutorial on youtube on flask: https://www.youtube.com/watch?v=Qr4QMBUPxWo
When the tutorial got the part where the person was describing best practices on project structuring, i ran into an issue where pycharm underlines the import statements red but the webapp that we were building seems to still work.
this was the folder structure in this part of the tutorial (the actual files are in this github page: https://github.com/jimdevops19/FlaskSeries/tree/master/06%20-%20Project%20Restructure)
Flask Market
├── market
│ ├── templates
│ │ ├── base.html
│ │ ├── home.html
│ │ └── market.html
│ ├── __init__.py
│ ├── market.db
│ ├── models.py
│ └── routes.py
└── run.py
the run.py script excecutes and the website will be launched no problem, but despite that, some of the import statements in the python files in the market package doesn't look right.
for example this is the code. from the __init__.py
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///market.db'
db = SQLAlchemy(app)
from market import routes
when i run just this script it will throw an error saying
ModuleNotFoundError: No module named 'market'
and this one is from the routes.py file
from market import app
from flask import render_template
from market.models import Item
@app.route('/')
@app.route('/home')
def home_page():
return render_template('home.html')
@app.route('/market')
def market_page():
items = Item.query.all()
return render_template('market.html', items=items)
when i run just this file, it also throws the same error
ModuleNotFoundError: No module named 'market'
but the webapp works fine, because only the run.py script is excecuted, i just feel like there is something wrong with how market is being imported. is there a correct way to call a variable or a function from the __init__.py ?