flask_url_mapping
Django-style url handling for Flask
Inspired by [https://stackoverflow.com/questions/31680048/django-styled-flask-url-pattern-for-large-application] 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 urls.py 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
- route to endpoint, http method default is GET
- route to endpoint with array of http methods
- route to component see Components
- 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
- wsgi.py
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)
flask_urls.register_urls(urls)
app.run()
- urls.py
from views import *
urls = [
("/", hello_world, ["GET"])
]
- views.py
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
Components
A component is a subfolder which contains at least an urls.py and an views.py When this folder also contains a templates directory, it will be automatically added to the jinja2 search path for html templates
Travis-CI
Release files for flask-url-mapping 0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask_url_mapping-0.6.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_url_mapping-0.6-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / flask_url_mapping-0.6.tar.gz
| Download URL | flask_url_mapping-0.6.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d42389a12089eb07f65edf48569846890642111c5e0288051f8213f51855dee7
|
|
BLAKE2b-256 checksum How to use checksums |
c7c2959f740197e59f2ae3cf9e93422a61bfbb3216317bb9d95a8768c3b4af0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Release files / flask_url_mapping-0.6-py2.py3-none-any.whl
| Download URL | flask_url_mapping-0.6-py2.py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
82f5a16b2a2333563117cbe99a3210b19167a69da1b013fed76b1ea6961a422f
|
|
BLAKE2b-256 checksum How to use checksums |
dd2098d98539466783af8ee41882819a43850653f9e8a65c5ebbf2d5a964fe2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|