Ejemplo n.º 1
0
def index():
    form = NameForm()
    if form.validate_on_submit():

        return redirect(url_for('.index'))
    return render_template('index.html',
    form = form)
Ejemplo n.º 2
0
def index():
    """主页"""
    # name = None
    form = NameForm()  # 创建NameForm实例用于表示表单
    if form.validate_on_submit():  # 第一次请求是不带表单数据的GET请求, 不进入

        # name = form.name.data  #
        # form.name.data = ''  #把字段数据重设为空字符串,请空字符串

        user = User.query.filter(User.username==form.name.data).first()
        if not user:
            user = User(username = form.name.data)

            db.session.add(user)
            session['known'] = False
            if current_app.config['FLASKY_ADMIN']:
                send_email(current_app.config['FLASKY_ADMIN'], 'New User', 'email/new_user', user=user)
        else:
            session['known'] = True

        session['name'] = form.name.data
        form.name.data = ''

        return redirect(url_for('.index'))  # 重定向, 实现刷新时不重复提交的效果
    return render_template('index.html', form=form, name=session.get('name'), known=session.get('known', False), current_time=datetime.utcnow())
Ejemplo n.º 3
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Parece que você alterou o nome!')
        session['name'] = form.name.data
        return redirect(url_for('.index'))
    return render_template('index.html', form=form, name=session.get('name'))
Ejemplo n.º 4
0
def user_info():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if not user:
            user = User(username=form.name.data)
            db.session.add(user)
            db.session.commit()
            session['known'] = False
        else:
            session['known'] = True
        session['name'] = form.name.data
        form.name.data = ''
    return render_template('user.html', name=session.get('name'), known=session.get('known', False), form=form)
Ejemplo n.º 5
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            session['person'] = 'new'
        else:
            session['person'] = 'old'
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('main.index'))
    return render_template('index.html', name=session.get('name'), form=form)
Ejemplo n.º 6
0
def index():
    form=NameForm()
    if form.validate_on_submit():
        user=User.query.filter_by(username=form.name.data).first()
        if user is None:
            user=User(username=form.name.data)
            db.session.add(user)
            session['known']=False
            if current_app.config['FLASKY_ADMIN']:
                send_email(current_app.config['FLASKY_ADMIN'],'New User','mail/new_user',user=user)
        else:
            session['known']=True
            session['name']=form.name.data
            return redirect(url_for('.index'))
    return render_template('index.html',form=form,name=session.get('name'),known=session.get('known',False))
Ejemplo n.º 7
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
        if user is None:
            user = User(username=form.name.data)
            db.session.add(user)
            async_send_mail('New Registration!', 'mail/new_registration', name=form.name.data)
            session['known'] = False
        else:
            session['known'] = True
        session['name'] = form.name.data
        form.name.data = ''
        return redirect(url_for('.index'))
    else:
        return render_template('index.html', form=form, name=session.get('name'), known=session.get('known', False))
Ejemplo n.º 8
0
def index():
    form = NameForm()
    if form.validate_on_submit():
        return redirect(url_for("index"))
    return render_template("index.html", form=form, name=session.get("name"), known=session.get("known", False),
                           current_time=datetime.utcnow())