今天被flask的项目结构或者说是蓝图搞得晕头转脑,各种文档也没说清,从github搜索并clone了几个用flask做成的网站,无奈水平太低,看不懂
记录一下今天学到的
蓝图
|-app/
|-|init.py
|-|views.py
|-|init.py
|-|templates/
|-|static/
|-config.py
|-run.py
|-tmp/
run.py
输入python run.py就可以运行程序
1from app import app #从app包中调用app模块
2app.run() #运行程序
config.py
一些基本的配置
1DEBUG = True #打开调试模式
app/init.py
1from flask import Flask, request, session, g, redirect, url_for, \
2 abort, render_template, flash
3
4app = Flask(__name__)
5app.config.from_object("config") #调用config.py配置文件
6
7from app import views #从app包中导入views模块
app/views.py
视图文件
1from app import app
2from flask import Flask, request, session, g, redirect, url_for, \
3 abort, render_template, flash
4@app.route.('/')
5def Index():
6 return 'hello,world'
7@app.route(/index)
8def Show_page():
9 return render_template('index.html')
app/templates/
放置模板
app/templates/index.html
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width">
6 <link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
7 #使用static文件夹中的css,js
8 <title>
9 hello
10 </title>
11
12 </head>
13 <body>
14 <ul>
15 <li>hello</li>
16 <li>world</li>
17 <li>hello world</li>
18 </ul>
19 </body>
20</html>
app/static
放置一些静态文件 css,js等
知识共享署名-非商业性使用-相同方式共享4.0国际许可协议