flask-urls is a collection of useful URL-related functions for Flask applications.
Install flask-urls with pip:
pip install -e 'hg+http://bitbucket.org/sjl/flask-urls@v0.9.2#egg=flask-urls'
pip install -e 'git+http://github.com/sjl/flask-urls.git@v0.9.2#egg=flask-urls'
flask-urls currently provides one function to make dealing with URLs in Flask applications a bit easier.
The permalink decorator was taken from this snippet on the Flask site. It’s used to wrap functions so they only need to return the arguments to Flask’s url_for function, instead of calling the function themselves.
For example, say you have several classes that represents items on your site:
from flask import url_for
class Event(object):
def __init__(self, event_id):
self.event_id = event_id
def link(self):
return url_for('event', event_id=self.event_id)
class User(object):
def __init__(self, username):
self.username = username
def link(self):
return url_for('profile', username=self.username)
Using the permalink decorator can make the link functions a bit cleaner:
from flaskext.urls import permalink
class Event(object):
def __init__(self, event_id):
self.event_id = event_id
@permalink
def link(self):
return 'event', { 'event_id': self.event_id }
class User(object):
def __init__(self, username):
self.username = username
@permalink
def link(self):
return 'profile', { 'username': self.username }
If you want to contribute feel free to fork the Mercurial repository or git repository and send a pull request.