Flask-Mime is Flask extension that enables applications to dispatch requests based on Accept header of it.
Install
Install the extension with the following command:
$ pip install Flask-Mime
Usage
Create a Mime object and define routes with MIME types:
from flask import Flask, render_template, jsonify
from flask_mime import Mime
app = Flask(__name__)
mimetype = Mime(app)
@mimetype('text/html')
@app.route('/')
def index_html():
return render_template('index.html')
@mimetype('application/json')
@app.route('/')
def index_json():
return jsonify(data={'content': 'index'})
Each requests are dispatched depending on the value of Accept header, even though they have same request path:
client = app.test_client()
client.get('/', headers={'Accept': 'text/html'}) # returns html
client.get('/', headers={'Accept': 'application/json'}) # returns json
Note
Note that MIME type based request dispatching mechanism may have negative influence for some applications, for example, which has a cache system.
Metadata
Release files for Flask-Mime 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distributions (sdists)
| File | Size | Uploaded | |
|---|---|---|---|
| Flask-Mime-0.1.0.zip | 10.3 kB | Details | |
| Flask-Mime-0.1.0.tar.gz | 5.4 kB | Details |
Release files / Flask-Mime-0.1.0.zip
| Download URL | Flask-Mime-0.1.0.zip |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60e816578bdd75ecd099ad732ec8ef1e0f4774df335e5126db0f9eee8be1388c
|
|
BLAKE2b-256 checksum How to use checksums |
14bff8b88bcf368b29517999093f796bacc26f5770647ec644667d923ef4aced
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Flask-Mime-0.1.0.tar.gz
| Download URL | Flask-Mime-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05991d7dfc62860493ed67f84aab2f0eb269a5318ab1b610b4036fc5ac96f6aa
|
|
BLAKE2b-256 checksum How to use checksums |
9d4370a55f1077992b5ed649fed16c1a7295f1234de54f45bc1d245c6f9b83b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |