flaskr.py
# flaskr.py
from flask import Flask
app = Flask(__name__)
import views
if __name__ == "__main__":
app.run()
views.py
# views.py
from flaskr import app
from flask import render_template, g
@app.route('/')
def show_entries():
entries = None
return render_template('show_entries.html', entries=entries)
python3 flaskr.py
Can anyone tell me why this isn't working but if i move the whole app into a separate package it works flawless.
No errors, not nothing except a 404 like the views.py is ignored. I'm knew to Flask and i'm trying out different things to understand how it actually works.
Thanks!
If you want to move views to other file you need to register blueprint:
flask.py
# flaskr.py
from flask import Flask
from .views import my_view
app = Flask(__name__)
app.register_blueprint(my_view)
if __name__ == "__main__":
app.run()
views.py
# views.py
from flaskr import app
from flask import render_template, g
my_view = Blueprint('my_view', __name__)
@app.route('/')
def show_entries():
entries = None
return render_template('show_entries.html', entries=entries)
Similar questions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With