from flask import Blueprint, render_template
from flask_security import login_required

admin = Blueprint('admin', __name__)


@admin.route('/')
@admin.route('/index')
@login_required
def index():
    return render_template('admin/index.html', title='Admin')

from flask import Blueprint, render_template, redirect, url_for
from flask_security import current_user

admin = Blueprint('admin', __name__)


@admin.route('/')
@admin.route('/index')
def index():
    return render_template('admin/index.html', title='Admin')


@admin.before_request
def require_login():
    if not current_user.is_authenticated:
        return redirect(url_for('security.login', next='admin'))

Move admin authentication into before_request handler
Move admin authentication into before_request handler

- from flask import Blueprint, render_template
+ from flask import Blueprint, render_template, redirect, url_for
- from flask_security import login_required
+ from flask_security import current_user
  
  admin = Blueprint('admin', __name__)
  
  
  @admin.route('/')
  @admin.route('/index')
- @login_required
  def index():
      return render_template('admin/index.html', title='Admin')
  
+ 
+ @admin.before_request
+ def require_login():
+     if not current_user.is_authenticated:
+         return redirect(url_for('security.login', next='admin'))
+ 
Move admin authentication into before_request handler
## Code Before:
from flask import Blueprint, render_template
from flask_security import login_required

admin = Blueprint('admin', __name__)


@admin.route('/')
@admin.route('/index')
@login_required
def index():
    return render_template('admin/index.html', title='Admin')

## Instruction:
Move admin authentication into before_request handler
## Code After:
from flask import Blueprint, render_template, redirect, url_for
from flask_security import current_user

admin = Blueprint('admin', __name__)


@admin.route('/')
@admin.route('/index')
def index():
    return render_template('admin/index.html', title='Admin')


@admin.before_request
def require_login():
    if not current_user.is_authenticated:
        return redirect(url_for('security.login', next='admin'))
