flask make response

This commit is contained in:
Matthew Scragg 2014-01-16 17:46:22 -06:00
parent a891e77d40
commit 55d587f6d0
2 changed files with 14 additions and 3 deletions

View file

@ -17,7 +17,7 @@ logging.getLogger('requests').setLevel(logging.WARNING)
import time
import sys
import os
import json
import httplib
import traceback
from flask import Flask, request, render_template, url_for, redirect, session, flash, g
@ -129,6 +129,19 @@ class Application(Flask):
print >> sys.stderr, ' * Ready in %.2fms' % (1000.0 * (time.time() - start_time))
def make_response(self, rv):
if rv is None:
rv = '', httplib.NO_CONTENT
elif not isinstance(rv, tuple):
rv = rv,
rv = list(rv)
if isinstance(rv[0], (list, dict)):
rv[0] = self.response_class(json.dumps(rv[0]), mimetype='application/json')
return super(Application, self).make_response(tuple(rv))
class RegexConverter(BaseConverter):
"""

View file

@ -70,8 +70,6 @@ def delete(name):
@blueprint.route("/wiki/_create/", defaults={'name': None}, methods=['GET', 'POST'])
@blueprint.route("/wiki/_create/<name>", methods=['GET', 'POST'])
def create(name):
if request.method == 'POST':
g.current_wiki.write_page(request.form['name'],
request.form['content'],