0
I have doubts about making my application as organized as possible, I’m having trouble implementing MVC ...
This is the file that starts the application
from flask import Flask
app = Flask(__name__,template_folder='template' )
app.run(debug=True)
This is the collection of Views
from flask import render_template, redirect, request
from App import app
from settings import REPOSITORY_NAME, REPOSITORY_SETTINGS
@app.route('/')
@app.route('/home')
def home():
return render_template(
'template.html')
Only I can’t get Templete to be rendered by render_template of a 404 error. What I might be doing wrong?
I managed to make it work that way:
runservice.py stayed that way
from project import app
if __name__ == '__main__':
app.run(debug = True)
Inside the Controllers folder we have the 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 projectct folder we have the init.py
from flask import Flask
app = Flask('project')
app.debug = True
from project.controllers import *
PS: I don’t know if it’s the best way to work, but I got the result! In case anyone has a better solution would like to know!
still giving 404
– André Felipe Jardim Firmo
I managed to do it another way, but I had to change the structure of "PROJECT", I’ll put it right down
– André Felipe Jardim Firmo