python flask,file structure ,blueprint简单应用
2017-07-23 19:41
309 查看
首先要新建flask工程
工程根目录下会自带static目录和templates目录
1.static目录存放网页静态文件,例如js文件,css文件,jpg文件,geojson文件,svg文件,csv文件等。
2.templates目录存放html文件
1.在工程根目录新建工程启动文件,命名为run.py
2.在工程根目录新建python后台包,索性命名为Transfer包(里面自带
3.在static目录下新建mycss.css文件
4.在templates下新建transfer目录,进入transfer目录新建ipmap.html文件
运行run.py文件
浏览器访问http://localhost:5000/transfer/ipmap即可看到Success!
工程根目录下会自带static目录和templates目录
1.static目录存放网页静态文件,例如js文件,css文件,jpg文件,geojson文件,svg文件,csv文件等。
2.templates目录存放html文件
1.在工程根目录新建工程启动文件,命名为run.py
2.在工程根目录新建python后台包,索性命名为Transfer包(里面自带
__init__.py文件)
#run.py from flask import Flask #引入后台包 from Transfer import transfer #实例化app app = Flask(__name__) #设置http://localhost:5000显示的内容 @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': #注册http://localhost:5000/transfer链接 app.register_blueprint(transfer,url_prefix='/transfer') #启动flask小型服务器,默认端口号5000 app.run()
#__init__.py from flask import Blueprint from flask import render_template #实例化transfer transfer = Blueprint('transfer',__name__) #注册http://localhost:5000/transfer/ipmap链接所绑定函数 @transfer.route('/ipmap', methods=['POST','GET']) #绑定函数,不同的链接绑定函数名不能相同 def ipmap(): #执行链接所返回的html文件 return render_template('/transfer/ipmap.html')
3.在static目录下新建mycss.css文件
body{ background: blue; }
4.在templates下新建transfer目录,进入transfer目录新建ipmap.html文件
<!--ipmap.html--> <html> <head> <meta charset="utf-8"> <title>Test</title> <link rel='stylesheet' href='../../static/mycss.css' type='text/css'/> </head> <body> <h1>Success!</h1> </body> </html>
运行run.py文件
浏览器访问http://localhost:5000/transfer/ipmap即可看到Success!
相关文章推荐
- 关于Python对简单的web框架flask的应用使得不只是本机而是局域网都能访问
- python3爬虫之入门和正则表达式,获取IP地址, 隐马尔可夫模型及其在分词中的简单应用
- 在Linux上使用Python和Flask创建你的第一个应用
- 【Python】简单应用-糗事百科
- python--flask框架的安装和简单使用
- Python练习(1):递归和动态规划的简单应用
- Python的os库简单应用
- Python yield的简单应用和理解
- 用python创建一个简单的restful风格的web服务应用
- python中stack在实际中的简单应用之平衡符号
- Python(2.7.x)数据库应用的简单示例
- python set 简单应用
- python中quests模块的简单应用
- python chardet简单应用
- Python: Windows下pip的安装及简单应用
- Python 线程和 redis 简单读写操作应用
- 应用:Python实现简单聊天程序
- 使用Flask快速开发WEB应用-第二篇:Blueprint模块的应用
- Python基于sklearn库的分类算法简单应用示例
- C++程序调用Python的函数(简单应用)及Ubuntu16.04下codeblocks的环境配置