flask render_template UnicodeDecodeError错误(或jinja2 UnicodeDecodeError错误)

时间:2019-07-08 09:10:16

标签: python flask jinja2

enter image description here

我正在研究烧瓶登录表单

它返回了这样的错误

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbc in position 431: invalid start byte

下面是login.html的代码

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block title %}
Login
{% endblock %}

{% block styles %}
{{super()}}
<link rel="stylesheet" href="{{url_for('.static', filename='signin.css')}}">
{% endblock %}

{% block content %}
<div class="container">

    <form class="form-signin" method="POST" action="/login">
        <h2 class="form-signin-heading">서비스를 이용하시려면 로그인이 필요합니다</h2>
        {{ form.hidden_tag() }}
        {{ wtf.form_field(form.username) }}
        {{ wtf.form_field(form.password) }}
        {{ wtf.form_field(form.remember) }}
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
    </form>

</div> <!-- /container -->
{% endblock %}

我猜login_form渲染器出错了

from flask import Flask, render_template, redirect, url_for
def login():
        form = LoginForm()

        if form.validate_on_submit():
            user = User.query.filter_by(username=form.username.data).first()
            if user:
                if check_password_hash(user.password, form.password.data):
                    login_user(user, remember=form.remember.data)
                    return redirect(url_for('dashboard'))

            return '<h1>Invalid username or password</h1>'
            #return '<h1>' + form.username.data + ' ' + form.password.data + '</h1>'

        return render_template('login.html', form=form)

“ guess스를이서비로그인이필요합니다”部分是我想应该编码的东西。但不幸的是,我通常是flask和web_development的新手,我认为我不了解jinja2和html文件如何正确地相互影响....您能回答我应该在哪里放置编码内容并解释一下为什么?

0 个答案:

没有答案