Routes with flask

-1

I'm trying to separate the functions of your routes, creating only one file for the routes and one file for each function, but when I try to call that function file on 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 \ corerin \ core__init __. py", line 20,   in       from core import routes File "C: \ Users \ Emerson Carbonaro \ Documents \ GitHub \ Nutrin \ corerin \ core \ routes.py", line 3, in          from controllers.index import index ModuleNotFoundError: No module named 'controllers'

  • If you are giving an error because this way of organizing is wrong, let's know kk
asked by anonymous 02.05.2018 / 15:03

1 answer

-1

Already able to solve the problem, importing the controllers should be done from the main module.

    
21.06.2018 / 14:50