<commit_before># coding: utf-8
from flask import Flask, render_template
from flask_script import Manager
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import Form
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)  # 实例化app
app.config['SECRET_KEY'] = 'secret_key_string'  # 用于加密 session 的密钥

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)


class NameForm(Form):
    '''Name表单类'''
    name = StringField('What is your name?', validators=[Required()])  # 文本字段
    submit = SubmitField('Submit')  # 提交按钮


@app.errorhandler(404)
def page_not_found(e):
    '''自定义404页面'''
    return render_template('404.html'), 404

@app.errorhandler(500)
def internal_server_error(e):
    '''自定义500页面'''
    return render_template('500.html'), 500

@app.route('/', methods=['GET', 'POST'])
def index():
    '''主页视图函数'''
    name = None
    form = NameForm()
    if form.validate_on_submit():  # 验证表单
        name = form.name.data
        form.name.data = ''
    return render_template('index.html', form=form, name=name)

if __name__ == '__main__':
    manager.run()
<commit_msg>User sessions and redirects<commit_after># coding: utf-8
from flask import Flask, render_template, session, redirect, url_for
from flask_script import Manager
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import Form
from wtforms import StringField, SubmitField
from wtforms.validators import Required

app = Flask(__name__)  # 实例化app
app.config['SECRET_KEY'] = 'secret_key_string'  # 用于加密 session 的密钥

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)


class NameForm(Form):
    '''Name表单类'''
    name = StringField('What is your name?', validators=[Required()])  # 文本字段
    submit = SubmitField('Submit')  # 提交按钮


@app.errorhandler(404)
def page_not_found(e):
    '''自定义404页面'''
    return render_template('404.html'), 404

@app.errorhandler(500)
def internal_server_error(e):
    '''自定义500页面'''
    return render_template('500.html'), 500

@app.route('/', methods=['GET', 'POST'])
def index():
    '''主页视图函数'''
    form = NameForm()
    if form.validate_on_submit():  # 验证表单
        session['name'] = form.name.data  # 使用会话保存 name
        return redirect(url_for('index'))
    return render_template('index.html', form=form, name=session.get('name'))

if __name__ == '__main__':
    manager.run()

{'fraction_non_alphanumeric': 0.13303315595579207, 'fraction_numerical': 0.020466639377814164, 'mean_word_length': 4.683720930232558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1802342', 'n_tokens_mistral': 891, 'n_tokens_neox': 862, 'n_words': 203}