Flask-Mime-0.1.0
توضیحات
Provides MIME type based request dispatching mechanism.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | Flask-Mime-0.1.0 |
| نام | Flask-Mime |
| نسخه کتابخانه | 0.1.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | lanius |
| ایمیل نویسنده | lanius@nirvake.org |
| آدرس صفحه اصلی | https://github.com/lanius/flask-mime/ |
| آدرس اینترنتی | https://pypi.org/project/Flask-Mime/ |
| مجوز | Copyright (c) 2014 by lanius. Some rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Flask-Mime
==========
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:
.. code-block:: bash
$ pip install Flask-Mime
Usage
-----
Create a Mime object and define routes with MIME types:
.. code-block:: python
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:
.. code-block:: python
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.
نحوه نصب
نصب پکیج whl Flask-Mime-0.1.0:
pip install Flask-Mime-0.1.0.whl
نصب پکیج tar.gz Flask-Mime-0.1.0:
pip install Flask-Mime-0.1.0.tar.gz