Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Django-style url handling for Flask

Project description


Django-style url handling for Flask

Inspired by [] this package is an attempt to generalize the concept of Django-like url-view / endpoint-mapping.

You can install it via

pip install flask-url-mapping

Centerpiece is an which contains the mapping.

urls = [
    ("/", views.index),                             #1
    ("/login", views.login, ["GET", "POST"]),       #2
    ("/home", "home.urls")                          #3
    ("/admin", views.admin, ["GET"], "admin_role"), #4

There are four ways to map routes to endpoints

  1. route to endpoint, http method default is GET
  2. route to endpoint with array of http methods
  3. route to component see Components
  4. route to endpoint with array of http methods and required role

After declaring your url mapping You can register the urls to the flask app via register_urls

A sample setup without permissions

from flask import Flask
from flask_url_mapping import register_urls
from urls import urls
app = Flask(__name__)

if __name__ == '__main__':
    flask_urls = FlaskUrls(app)
from views import *
urls = [
    ("/", hello_world, ["GET"])
def hello_world():
    return 'Hello World!'    

A sample setup with permissions

When adding a role to a route endpoint mapping your project has to use flask_login


A component is a subfolder which contains at least an and an When this folder also contains a templates directory, it will be automatically added to the jinja2 search path for html templates


Build Status

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flask-url-mapping, version 0.6
Filename, size File type Python version Upload date Hashes
Filename, size flask_url_mapping-0.6-py2.py3-none-any.whl (4.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size flask_url_mapping-0.6.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page