开始Flask项目

from flask import Flask,render_template  #从flask这个框架中导入Flask这个类

app = Flask(__name__) #初始化一个Flask对象,需要传递一个参数__name__


@app.route('/')#是一个装饰器,在函数上面, 其作用是做一个URL与视图函数的映射,127.0.0.1:5000/ 去执行hello_world()函数
def index():
    return render_template('index.html')

@app.route('/login/')
def login():
    return render_template('login.html')

@app.route('/music/163.com/')
def music():
    return render_template('base.html')

if __name__ == '__main__': #当前这个文件作为主程序运行,就会执行这段,作为模块就不会
    app.run(debug=True) #启动一个web服务器,来监听并接受用户的请求。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link  type="text/css" rel="stylesheet" href="{{ url_for('static',filename='css/index.css') }}">
</head>

<body>

<img src="{{ url_for('static',filename='img/网易云.jpg') }}" alt="" width="40px">
<h2>欢迎登录网易云音乐</h2>
<a href="http://music.163.com/">首页</a>
<a href="http://music.163.com/login">登录</a>
<a href="{{ url_for('login') }}">注册</a>

</body>
</html>

posted on 2017-11-03 17:54  张木清  阅读(116)  评论(0编辑  收藏  举报

导航