- 用url_for加载静态文件
- <script src="{ { url_for('static',filename='js/login.js') }}"></script>
- flask 从static文件夹开始寻找
- 可用于加载css, js, image文件
- 继承和扩展
- 把一些公共的代码放在父模板中,避免每个模板写同样的内容。base.html
- 子模板继承父模板
- {% extends 'base.html’ %}
- 父模板提前定义好子模板可以实现一些自己需求的位置及名称。block
- <title>{% block title %}{% endblock %}-MIS问答平台</title>
- {% block head %}{% endblock %}
- {% block main %}{% endblock %}
- 子模板中写代码实现自己的需求。block
- {% block title %}登录{% endblock %}
- 首页、登录页、注册页都按上述步骤改写。
from flask import Flask,render_templateapp = Flask(__name__)@app.route('/')def shouye(): return render_template('shouye.html')@app.route('/denglu/')def denglu(): return render_template('denglu.html')@app.route('/zhuce/')def zhuce(): return render_template('zhuce.html')if __name__ == '__main__': app.run()
{% block title %} 爱奇艺 {% endblock %} {% block js %}{% endblock %}
{% block jiemian %}推荐{% endblock %}
{% extends'shouye.html' %}{% block title %}用户登录{% endblock %}{% block js %} {% endblock %}{% block jiemian %}{% endblock %}用户登录
用户名密码普通用户 VIP用户
{% extends'shouye.html' %}{% block title %}用户注册{% endblock %}{% block js %} {% endblock %}{% block jiemian %}{% endblock %}新用户注册
用户昵称输入密码确认密码普通用户 VIP用户
function myLogin() { var one=document.getElementById("un"); var two=document.getElementById("pw"); var three=document.getElementById("error_box"); var four=document.getElementById("tpw"); if(two.value.length<6){ three.innerHTML="为了账号安全,请输入6个以上的密码!"; return } else if((one.value.charCodeAt(0)>=48)&&one.value.charCodeAt(0)<=57){ three.innerHTML="账号首个不能为数字!"; return } else if (two.value!=four.value){ three.innerHTML="输入密码不一致!请重新输入!"; return } else for(var i=1;i57)&&(one.value.charCodeAt(i)<97||one.value.charCodeAt(i)>122)){ three.innerHTML="账号只能为数字!"; return } } if(one.value.length<6){ three.innerHTML="账号需为6-12个长度!"; return } window.alert("登录成功!") }
function myLogin() { var one=document.getElementById("un"); var two=document.getElementById("pw"); var three=document.getElementById("error_box"); if(two.value.length<6){ three.innerHTML="为了账号安全,请输入6个以上的密码!"; return } else if((one.value.charCodeAt(0)>=48)&&one.value.charCodeAt(0)<=57){ three.innerHTML="账号首个不能为数字!"; return } else for(var i=1;i57)&&(one.value.charCodeAt(i)<97||one.value.charCodeAt(i)>122)){ three.innerHTML="账号只能为数字!"; return } } if(one.value.length<6){ three.innerHTML="账号需为6-12个长度!"; return } window.alert("登录成功!") }
img{ width: 300px; height: 200px;}.img{ border:1px solid skyblue; width: 300px; height: 250px; float: left; margin: 5px;}.img img{ width:100%; height: 85%;}.desc{ text-align:center; padding: 5px;}.img:hover{ border: 1px solid blue;}p{ color:fuchsia;}.kk{ color:darkcyan;font-weight: bold;font-style: italic;font-size: 20px;}#abc{ color: darkblue;text-decoration: underline;font-size: 25px;}.aaa img{ height:50px; width:50px;}