Created
October 31, 2011 20:55
-
-
Save tanelpuhu/1328911 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render(view, data = None): | |
current_dir = os.path.dirname(__file__) | |
path = os.path.abspath( | |
os.path.join(current_dir, '..', 'views', '%s.html' % view) | |
) | |
if not os.path.exists(path): | |
return '404 - view not found!' | |
if data is None: | |
data = {} | |
return template.render(path, data) | |
def view(view_name): | |
def decorator(f): | |
def decorated_function(*args, **kwargs): | |
self = args[0] | |
data = f(*args, **kwargs) | |
self.out(render(view_name, data)) | |
return decorated_function | |
return decorator | |
class MainHandler(BaseHandler): | |
@view('index') | |
def get(self): | |
return { | |
'login' : users.CreateLoginURL('.') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment