from flask import Flask, render_template,request,redirect,url_for
from flask_sqlalchemy import SQLAlchemy
import config
app = Flask(__name__)
app.config.from_object(config)
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(20), nullable=False)
password = db.Column(db.String(20), nullable=False)
nickname = db.Column(db.String(50))
#增
#user = User(username ='ccccls',password='111111' )
#db.session.add(user)
#db.session.commit()
#查
#user=User.query.filter(User.username =='ccccls').first()
#print(user.username,user.password)
#删
#user=User.query.filter(User.username =='ccccls').first()
#db.session.delete(user)
3db.session.commit()
#改
#user=User.query.filter(User.username =='ccccls').first()
#user.password='ccccls'
#db.session.commit()
#db.create_all()
@app.route('/base/')
def base():
return render_template('base.html')
@app.route('/login/')
def login():
return render_template('login.html')
@app.route('/register/', methods=['GET','POST'])
def register():
if request.method=='GET':
return render_template('register.html')
else:
usern=request.form.get('username')
nickn = request.form.get('nickname')
passw= request.form.get('password')
user=User.query.filter(User.username==username).first()
if user:
return u'username existed'
else:
user=User(username=username,password=password)
db.session.add(user)
db.session.commit()
return redirect(url_for('login'))
@app.route('/question/')
def question():
return render_template('question.html')
@app.route('/index/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
</nav>
{% block main %} <p>{{ username }}xyjie</p>
{% endblock %}
<link rel="stylesheet" type="text/css" href="xyjie.css">
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body id="mybody">
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">首页</a>
</div>
<div>
<ul class="nav navbar-nav">
<li><a href="#" onclick="">登陆</a></li>
<li><a href="#" onclick="">注册</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
设置 <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#">收藏</a></li>
<li><a href="#">分享</a></li>
<li><a href="#">搜索</a></li>
<li class="divider"></li>
<li><a href="#">点赞</a></li>
</ul>
</li>
<li><a href="#">||</a></li>
</ul>
</div>
<div style="float: left">
<img id="myonoff" onclick="mySwitch()" src="http://p0.so.qhimgs1.com/bdr/200_200_/t01d734a105379159dc.gif" style width="40px" >
</div>
<div>
<input type="text" name="user" id="user" placeholder="请输入内容">
<input type="button" value="搜索" class="btn btn-success" onclick="">
</div>
</div>
</nav>
<nav class="navbar navbar-inverse navbar-fixed-bottom" role="navigation">
<ul class="nav navbar-nav">
<li><img src="http://www.gzcc.cn/2016/images/footer1-logo.png"></li>
<li style="color: bisque;">版权所有@xyjie</li>
</ul>
</nav>
<div>
<div class="sa">
<a href="http://desk.zol.com.cn/"><img
src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2330928080,25031233&fm=27&gp=0.jpg"></a>
<div class="st"><a href="http://desk.zol.com.cn/">花花华晨宇1</a></div>
</div>
<div class="sa">
<a href="http://desk.zol.com.cn/"><img
src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3605928156,2200570185&fm=27&gp=0.jpg"></a>
<div class="st"><a href="http://desk.zol.com.cn/">花花华晨宇2</a></div>
</div>
<div class="sa">
<a href="http://desk.zol.com.cn/"><img
src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2787456122,2827006597&fm=27&gp=0.jpg"></a>
<div class="st"><a href="http://desk.zol.com.cn/">花花华晨宇3</a></div>
</div>
<div class="sa">
<a href="http://desk.zol.com.cn/"><img
src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2478028302,36965079&fm=27&gp=0.jpg"></a>
<div class="st"><a href="http://desk.zol.com.cn/">花花华晨宇4</a></div>
</div>
</div>
</footer>