from flask import Blueprint, request, url_for, render_template
from flask.ext.security import current_user

play = Blueprint('play', __name__, template_folder='templates')


@play.route('/')
def index():
    api_token = current_user.api_token
    return render_template('play/index.html', api_token=api_token)

from flask import Blueprint, request, url_for, render_template
from flask import redirect
from flask.ext.security import current_user, AnonymousUser

play = Blueprint('play', __name__, template_folder='templates')


@play.route('/')
def index():
    if hasattr(current_user, 'api_token'):
        api_token = current_user.api_token
        return render_template('play/index.html', api_token=api_token)
    else:
        return redirect('/account/login')

Fix error if anonymous user is logged in, instead redirect to login page
Fix error if anonymous user is logged in, instead redirect to login page

  from flask import Blueprint, request, url_for, render_template
+ from flask import redirect
- from flask.ext.security import current_user
+ from flask.ext.security import current_user, AnonymousUser
  
  play = Blueprint('play', __name__, template_folder='templates')
  
  
  @play.route('/')
  def index():
+     if hasattr(current_user, 'api_token'):
-     api_token = current_user.api_token
+         api_token = current_user.api_token
-     return render_template('play/index.html', api_token=api_token)
+         return render_template('play/index.html', api_token=api_token)
+     else:
+         return redirect('/account/login')
  
Fix error if anonymous user is logged in, instead redirect to login page
## Code Before:
from flask import Blueprint, request, url_for, render_template
from flask.ext.security import current_user

play = Blueprint('play', __name__, template_folder='templates')


@play.route('/')
def index():
    api_token = current_user.api_token
    return render_template('play/index.html', api_token=api_token)

## Instruction:
Fix error if anonymous user is logged in, instead redirect to login page
## Code After:
from flask import Blueprint, request, url_for, render_template
from flask import redirect
from flask.ext.security import current_user, AnonymousUser

play = Blueprint('play', __name__, template_folder='templates')


@play.route('/')
def index():
    if hasattr(current_user, 'api_token'):
        api_token = current_user.api_token
        return render_template('play/index.html', api_token=api_token)
    else:
        return redirect('/account/login')
