Reputation: 2661
I'm trying to create a flask app using blueprints, so I have this structure:
myapp/
__init__.py
static/
templates/
site/
index.html
register.html
layout.html
views/
__init__.py
site.py
models.py
__init__.py
from flask import Flask
from .views.site import site
app = Flask(__name__)
app.register_blueprint(site)
views/site.py
from flask import Blueprint, render_template
site = Blueprint('site', __name__)
site.route('/')
def index():
return render_template('site/index.html')
site.route('/register/')
def register():
return render_template('site/register.html')
When I run the app, and try to go to any of the routes I have, the only thing I gest is a "404 Not Found" and I don't really know what I'm doing wrong, because I'm doing exactly what this book says: Explore Flask - Blueprints
Thanks in advance.
Upvotes: 1
Views: 1442
Reputation: 1923
You have to prepend @
to site.route
like the following.
from flask import Blueprint, render_template
site = Blueprint('site', __name__)
@site.route('/')
def index():
return render_template('site/index.html')
@site.route('/register/')
def register():
return render_template('site/register.html')
Upvotes: 4