I have doubts about making my application as organized as possible, I'm having a hard time implementing MVC ...
Thisisthefilethatlaunchestheapplication
fromflaskimportFlaskapp=Flask(__name__,template_folder='template')app.run(debug=True)
ThisistheViewsfile
fromflaskimportrender_template,redirect,requestfromAppimportappfromsettingsimportREPOSITORY_NAME,[email protected]('/')@app.route('/home')defhome():returnrender_template('template.html')
Ijustcannotgetthetempleterenderedbyrender_templategivesa404error.WhatcanIbedoingwrong?
Imanagedtomakeitworkthatway:
runservice.py stayed that way
from project import app
if __name__ == '__main__':
app.run(debug = True)
In the Controllers folder we have init .py and views.py
init .py
import os, glob
__all__ = [os.path.basename(f)[:-3]
for f in glob.glob(os.path.dirname(__file__)+'/*.py')]
Views.py
from project import app
from flask import render_template, request
from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired
class CreateForm(FlaskForm):
texto = StringField('name', validators=[DataRequired])
@app.route('/')
def home():
return render_template('printer/index.html')
In the root of the proyecct folder we have init .py
from flask import Flask
app = Flask('project')
app.debug = True
from project.controllers import *
PS: I do not know if this is the best way to work, but I got the expected result! If someone has a better solution I would like to know!