Skip to content

Commit d08cd4c

Browse files
committed
add python-flask-cors
1 parent e5f4764 commit d08cd4c

File tree

11 files changed

+11788
-0
lines changed

11 files changed

+11788
-0
lines changed

python-flask-cors/bootstrap-less-cors/dist/js/less-3.11.1.js

Lines changed: 11548 additions & 0 deletions
Large diffs are not rendered by default.

python-flask-cors/bootstrap-less-cors/dist/js/less-3.11.1.min.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet/less" type="text/css" href="testless.less">
7+
<script src="dist/js/less-3.11.1.min.js"></script>
8+
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/3.11.1/less.min.js" ></script> -->
9+
<!-- <script src="https://cdn.bootcss.com/less.js/3.11.1/less.min.js"></script> -->
10+
<title>Test less语法</title>
11+
</head>
12+
<body>
13+
<h2>测试Less</h2>
14+
<p>上面H2标题里的内容会被更新为绿色</p>
15+
</body>
16+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@color: #4d926F;
2+
3+
#header {
4+
color: @color;
5+
}
6+
7+
h2 {
8+
color: @color;
9+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Feb 13 10:20:54 2018
4+
"""
5+
6+
PGMname = 'PGM:python_learning_flask_cors'
7+
8+
from flask import Flask
9+
from flask import request
10+
from flask import render_template
11+
from flask_bootstrap import Bootstrap
12+
from flask_moment import Moment
13+
from datetime import datetime
14+
15+
app = Flask(__name__)
16+
moment = Moment(app)
17+
bootstrap = Bootstrap(app)
18+
19+
@app.route('/',methods=['GET','POST'])
20+
def home():
21+
current_time=datetime.utcnow()
22+
return render_template('index.html', current_time=current_time)
23+
24+
@app.route('/signin',methods=['GET'])
25+
def signin_form():
26+
return '''
27+
<form action='/signin' method='post'>
28+
<p><input name='username'></p>
29+
<p><input name='password' type='password'></p>
30+
<p><button type='submit'>Sign In</button></p>
31+
</form>
32+
'''
33+
34+
@app.route('/signin',methods=['post'])
35+
def signin():
36+
# 需要从request对象读取表单内容
37+
if request.form['username'] == 'admin' and \
38+
request.form['password'] == 'password':
39+
return '<h3>Hello,admin!</h3>'
40+
41+
return '<h3>Bad username or password.</h3>'
42+
43+
44+
@app.route('/user/<name>')
45+
def user(name):
46+
return render_template('user.html',name=name)
47+
48+
49+
if __name__ == '__main__':
50+
51+
app.run(debug=True, port=8000)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Feb 13 10:20:54 2018
4+
"""
5+
6+
PGMname = 'PGM:python_learning_flask_cors_momentjs'
7+
8+
from flask import Flask
9+
from flask import render_template
10+
app = Flask(__name__)
11+
12+
@app.route('/', methods=['GET','POST'])
13+
def home():
14+
return render_template('main.html')
15+
16+
if __name__ == '__main__':
17+
app.run(debug=True, port=8000)
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{% extends "bootstrap/base.html" %}
2+
3+
{% block head %}
4+
<!-- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script> -->
5+
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script> -->
6+
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-3.4.1.min.js"></script> -->
7+
{{ super() }}
8+
9+
<link rel="shortcut icon" href="{{ url_for('static',filename='favicon.ico') }}"
10+
type="image/x-icon">
11+
<link rel="icon" href="{{ url_for('static',filename='favicon.ico') }}"
12+
type="image/x-icon">
13+
14+
{% block script %}
15+
{{ moment.include_jquery() }}
16+
{{ moment.include_moment() }}
17+
{% endblock %}
18+
19+
{% endblock %}
20+
21+
22+
{% block title %}
23+
Flasky - Welcome
24+
{% endblock %}
25+
26+
{% block navbar %}
27+
<div class="navbar navbar-inverse" role="navigation">
28+
<div class="container">
29+
<div class="navbar-header">
30+
<button type="button" class="navbar-toggle"
31+
data-toggle="collapse" data-target=".navbar-collapse">
32+
<span class="sr-only"> Toggle navigation </span>
33+
<span class="icon-bar"></span>
34+
<span class="icon-bar"></span>
35+
<span class="icon-bar"></span>
36+
</button>
37+
<a class="navbar-brand" href="/"> Flasky </a>
38+
</div>
39+
<div class="navbar-collapse collapse">
40+
<ul class="nav navbar-nav">
41+
<li><a href="/"> Home </a></li>
42+
</ul>
43+
</div>
44+
</div>
45+
</div>
46+
{% endblock %}
47+
48+
{% block content %}
49+
<div class="container">
50+
{% for message in get_flashed_messages() %}
51+
<div class="alert alert-warning">
52+
<button type="button" class="close" data-dismiss="alert"> &times;</button>
53+
{{ message }}
54+
</div>
55+
{% endfor %}
56+
57+
{% block page_content %}
58+
{% endblock %}
59+
</div>
60+
{% endblock %}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% extends "base.html" %}
2+
3+
{% import "bootstrap/wtf.html" as wtf %}
4+
5+
{% block title %}Flasky - Hello{% endblock %}
6+
7+
{% block page_content %}
8+
<div class="container">
9+
<div class="page-header">
10+
<h1> Welcome to flasky page!</h1>
11+
<h1> Hello, {% if name %}
12+
{{ name }}
13+
{% else %}
14+
Stranger
15+
{% endif %}
16+
</h1>
17+
{% if not known %}
18+
<p> Pleased to meet you! </p>
19+
{% else %}
20+
<p> Happy to see you again! </p>
21+
{% endif %}
22+
<p> Orignal time is {{ current_time }} </p>
23+
<p> The local date and time is: {{ moment(current_time).format('LLL') }} </p>
24+
<p> That was: {{ moment(current_time).fromNow(refresh=True) }} </p>
25+
</div>
26+
27+
</div>
28+
{% endblock %}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<script src="//code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
7+
<script crossorigin="anonymous" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js" integrity="sha256-AdQN98MVZs44Eq2yTwtoKufhnU+uZ7v2kXnD5vqzZVo=" ></script>
8+
<script>
9+
moment.locale("en");
10+
function flask_moment_render(elem) {
11+
$(elem).text(eval('moment("' + $(elem).data('timestamp') + '").' + $(elem).data('format') + ';'));
12+
$(elem).removeClass('flask-moment').show();
13+
}
14+
function flask_moment_render_all() {
15+
$('.flask-moment').each(function() {
16+
flask_moment_render(this);
17+
if ($(this).data('refresh')) {
18+
(function(elem, interval) {
19+
setInterval(function() {
20+
flask_moment_render(elem) }, interval); })(this, $(this).data('refresh'));
21+
}
22+
})
23+
}
24+
$(document).ready(function() {
25+
flask_moment_render_all();
26+
});
27+
</script>
28+
<title>测试Moment.js</title>
29+
</head>
30+
<body>
31+
<h2>测试Moment.js是否能被加载成功</h2>
32+
<p>Moment.js预期在Chrome浏览器能够加载成功;在Safari浏览器会遇到CORS报错</p>
33+
34+
<p> Orignal time is 2020-04-21 08:39:41.238502 </p>
35+
<p> The local date and time is: <span class="flask-moment" data-timestamp="2020-04-21T08:39:41Z" data-format="format('LLL')" data-refresh="0" style="display: none">2020-04-21T08:39:41Z</span> </p>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)