ラベル bottle の投稿を表示しています。 すべての投稿を表示
ラベル bottle の投稿を表示しています。 すべての投稿を表示

2014年3月3日月曜日

python3 + bottleでshif-jisなcsvを出力する

無駄に悩んだ。
取り敢えずメモ程度に。
from io import StringIO
from bottle import route, response
@route('/get_csv')
def get_csv():
    response.content_type = 'application/octet-stream'
    response.headers['Content-Disposition'] = "attachment; filename='hoge.csv'"
    stream = StringIO()
    writecsv = csv.writer(stream)
        # ここでcsvを作る。
    stream.seek(0)
    return stream.getvalue().encode('shift-jis')

2013年9月18日水曜日

Python bottleでPOST時の項目数上限

Pythonのbottleを使ったWebサイトで、100個以上の項目(inputとかtextarea)を投げると100個までしか取得出来ない問題が起きた。

調べたらどうやら100個制限してるのが仕様っぽい
THE REQUEST OBJECT

んで取り敢えずこの設定を上書きすれば100この制限は外れるっぽい。

そのWeb全てのqueryに適用する場合はbottle読み込んでる所の一番上にかく。

from bottle import BaseRequest
BaseRequest.MAX_PARAMS = 200

各ページ個別で上限を設定する場合は

from bottle import BaseRequest
@route('/create', method='POST')
@view('confirm')
def post_create():
    BaseRequest.MAX_PARAMS = 200
    value = request.forms.decode().get('key')

となる。
まぁSecurityとか考えたら個別で設定だよな。