在Flask应用中更改setlocale无效

时间:2019-05-21 18:16:52

标签: python flask calendar locale

在我的烧瓶应用程序中,我想将语言环境设置更改为“ nl_NL”,以便可以使用荷兰语创建calendar.day_name [],但这无效。

我正在docker容器中运行flask应用

下面的代码中的day变量以英语保存。

我曾尝试在我的 init .py文件中设置区域设置,但未成功

import locale
import calendar
import time
locale.setlocale(locale.LC_ALL, 'nl_NL.utf-8')

@urenbon_blueprint.route('/hours/add', methods=['GET' , 'POST'])
@login_required
def hours_add():
    form = UrenBonForm(request.form)
    if form.validate_on_submit():
        date_object = datetime.strptime(form.date.data, '%d-%m-%Y')
        year = datetime.date(date_object).year
        week = datetime.date(date_object).isocalendar()[1]
        day_int = datetime.date(date_object).isocalendar()[2]
        day = calendar.day_name[day_int]
        total_morning = (int(request.form["hours_morning"]) * 60) + (int(request.form['minutes_morning']))
        total_afternoon = (int(request.form["hours_afternoon"]) * 60) + (int(request.form['minutes_afternoon']))
        total_minutes = ((int(request.form["hours_morning"]) * 60) + (int(request.form['minutes_morning'])))+((int(request.form["hours_afternoon"]) * 60) + (int(request.form['minutes_afternoon'])))
        created = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        urenbon = UrenBon(user_id=current_user.id, created=created,date=date_object,year=year,week=week, day=day,milking_morning=form.milking_morning.data,milking_afternoon=form.milking_afternoon.data,hours_morning=form.hours_morning.data, minutes_morning=form.minutes_morning.data, hours_afternoon=form.hours_afternoon.data, minutes_afternoon=form.minutes_afternoon.data, work_description=form.work_description.data, total_morning=total_morning, total_afternoon=total_afternoon, total_minutes=total_minutes)
        db.session.add(urenbon)
        db.session.commit()
        if 'url' in session:
            return redirect(session['url'])
    return render_template('new_hours.html', form=form, title='Vroege - Uren toevoegen')

0 个答案:

没有答案