5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Flask-paginateの表示文言の日本語化

Posted at

概要

Flaskで簡単にページング機能を実装しようとした際、Flask-paginateが便利です。
しかし、Flask-paginateで表示した場合、表示される文言が英語で表示されてしまう為、
日本語のアプリを作る際にそのままでは使用できません。
今回は、Flask-paginateでの表示文言の日本語化方法を記載します。

前提条件

  • Flask
  • Flask-paginate

方法

  • Paginateクラスをインスタンス化する際にdisplay_msgを引数に設定する
sample.py
from flask import Flask, Response, render_template, request
from flask_bootstrap import Bootstrap
from flask_paginate import Pagination, get_page_parameter

@app.route('/index')
def index():

    page_disp_msg = '表示範囲 <b>{start}件 - {end}件 </b> 合計:<b>{total}</b>件'

    result = get_index()

    page = request.args.get(get_page_parameter(), type=int, default=1)
    res = result[(page - 1)*pagination_page: page*pagination_page]
    pagination = Pagination(page=page, total=len(
        result), per_page=pagination_page, css_framework='bootstrap4', display_msg=page_disp_msg)

    return render_template('index.html', data=res, pagination=pagination)

表示結果

無題.png

参考

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?