3

This is really strange but am facing this problem. Everything was working and i was almost done with the app but out of a sudden it stopped. I have isolated the code and i realized that when i register a blueprint and use it on a route, it fails to return saying no URL found. Here is the isolated code:

from flask import Flask, render_template, Blueprint

app = Flask(__name__)

home = Blueprint('home', __name__, static_folder='static', template_folder='template')
app.register_blueprint(home)


@home.route('/')  #<---This one does not work
# @app.route('/') <--- This one works
def index():
    return "This is the index route."
    # return render_template('layer.html')


if __name__ == '__main__':
    app.run()
Samurai Jack
  • 2,985
  • 8
  • 35
  • 58
demerit
  • 141
  • 1
  • 9

1 Answers1

14

Move the app.register_blueprint(home) after route defined.

from flask import Flask, Blueprint

app = Flask(__name__)

home = Blueprint('home', __name__, static_folder='static', template_folder='template')

@home.route('/')  
def index():
    return "This is the index route."

app.register_blueprint(home)

if __name__ == '__main__':
    app.run()
stamaimer
  • 6,227
  • 5
  • 34
  • 55