-1
I am trying to separate the functions of its routes, creating only a file for the routes and a file for each function, but when I try to call this file from the function in routes it does not find it:
Routes.py :
from controllers.index import index
@app.route("/")
def indexRoute():
return index()
index py. :
from flask import render_template
def index():
return render_template('index.html')
init.py :
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_login import LoginManager
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
lm = LoginManager()
lm.init_app(app)
from core.models import tables
from core import routes
error:
(venv) C: Users Emerson Carbonaro Documents Github Nutrin nutrin>run.py runserver Traceback (Most recent call last): File "C: Users Emerson Carbonaro Documents Github Nutrin nutrin run.py", line 1, in from core import app, manager File "C: Users Emerson Carbonaro Documents Github Nutrin nutrin core__init__.py", line 20, in from core import Routes File "C: Users Emerson Carbonaro Documents Github Nutrin nutrin core Routes.py", line 3, in from controllers.index import index Modulenotfounderror: No module named 'controllers'
- In case you are making a mistake because this way of organizing is wrong, warn kk
The
controllers
is in the same folder as theroutes.py
?– Onilol