Views are all in located in the modules package, which contains blueprints Also, use alert-warning instead of alert-error for Bootstrap3master
							parent
							
								
									0f142a65e8
								
							
						
					
					
						commit
						3a411b4abe
					
				| @ -0,0 +1 @@ | |||||||
|  | '''Blueprint modules for {{cookiecutter.repo_name}}.''' | ||||||
| @ -0,0 +1,14 @@ | |||||||
|  | # -*- coding: utf-8 -*- | ||||||
|  | '''Members-only module, typically including the app itself. | ||||||
|  | ''' | ||||||
|  | from flask import Blueprint, render_template | ||||||
|  | from {{cookiecutter.repo_name}}.utils import login_required | ||||||
|  | 
 | ||||||
|  | blueprint = Blueprint('member', __name__, | ||||||
|  |                         static_folder="../static", | ||||||
|  |                         template_folder="../templates") | ||||||
|  | 
 | ||||||
|  | @blueprint.route("/members/") | ||||||
|  | @login_required | ||||||
|  | def members(): | ||||||
|  |     return render_template("members.html") | ||||||
| @ -0,0 +1,22 @@ | |||||||
|  | # -*- coding: utf-8 -*- | ||||||
|  | '''Helper utilities and decorators.''' | ||||||
|  | from flask import session, flash, redirect, url_for | ||||||
|  | from functools import wraps | ||||||
|  | 
 | ||||||
|  | def flash_errors(form): | ||||||
|  |     '''Flash all errors for a form.''' | ||||||
|  |     for field, errors in form.errors.items(): | ||||||
|  |         for error in errors: | ||||||
|  |             flash("Error in the {0} field - {1}" | ||||||
|  |                     .format(getattr(form, field).label.text, error), 'warning') | ||||||
|  | 
 | ||||||
|  | def login_required(test): | ||||||
|  |     '''Decorator that makes a view require authentication.''' | ||||||
|  |     @wraps(test) | ||||||
|  |     def wrap(*args, **kwargs): | ||||||
|  |         if 'logged_in' in session: | ||||||
|  |             return test(*args, **kwargs) | ||||||
|  |         else: | ||||||
|  |             flash('You need to log in first.') | ||||||
|  |             return redirect(url_for('home')) | ||||||
|  |     return wrap | ||||||
					Loading…
					
					
				
		Reference in new issue