skip to navigation
skip to content

Not Logged In

Flask-Mime 0.1.0

Provides MIME type based request dispatching mechanism.

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.

 
File Type Py Version Uploaded on Size
Flask-Mime-0.1.0.tar.gz (md5) Source 2014-02-19 5KB
Flask-Mime-0.1.0.zip (md5) Source 2014-02-19 10KB
  • Downloads (All Versions):
  • 12 downloads in the last day
  • 52 downloads in the last week
  • 280 downloads in the last month