flask web開發(四) web表單 csrf,重定向
# -*- coding: cp936 -*- import os import sys import logging.config import flask import socket from flask import Flask,jsonify from flask import request from flask import abort from flask import redirect from flask import make_response from flask_wtf import Form from flask import render_template,session,url_for,flash from wtforms import StringField,SubmitField from wtforms.validators import Required from flask_bootstrap import Bootstrap app = Flask(__name__)app.config['SECRET_KEY']='hard to guess string'
bootstrap=Bootstrap(app)app.config.from_pyfile('config.py')
class NameForm(Form): name=StringField('What is your name?',validators=[Required()]) submit=SubmitField('Submit')
user.html
{% extends "base45.html" %}{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Flasky{% endblock %}
{% block page_content %} <div class="page-header"> <h1>Hello,{% if name %}{{name}}{% else %} Strange!{% endif %}</h1> </div>{{wtf.quick_form(form)}} {% endblock %}