Skip to main content

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.

Download files

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

Source Distributions

Flask-Mime-0.1.0.zip (10.3 kB view details)

Uploaded Source

Flask-Mime-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file Flask-Mime-0.1.0.zip.

File metadata

  • Download URL: Flask-Mime-0.1.0.zip
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-Mime-0.1.0.zip
Algorithm Hash digest
SHA256 60e816578bdd75ecd099ad732ec8ef1e0f4774df335e5126db0f9eee8be1388c
MD5 3c113c4c56397b231452027650e9cfd3
BLAKE2b-256 14bff8b88bcf368b29517999093f796bacc26f5770647ec644667d923ef4aced

See more details on using hashes here.

File details

Details for the file Flask-Mime-0.1.0.tar.gz.

File metadata

  • Download URL: Flask-Mime-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-Mime-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05991d7dfc62860493ed67f84aab2f0eb269a5318ab1b610b4036fc5ac96f6aa
MD5 da68e86ca1df2be711b45d28b63f5a0f
BLAKE2b-256 9d4370a55f1077992b5ed649fed16c1a7295f1234de54f45bc1d245c6f9b83b9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page