From 8ac3b4d1db506d95a67544540b1c036746afdc12 Mon Sep 17 00:00:00 2001 From: Grey Li Date: Fri, 10 Mar 2023 08:57:54 +0800 Subject: [PATCH] Add longtalk ajax example --- examples/longtalk/app.py | 16 +++++ examples/longtalk/static/favicon.ico | Bin 0 -> 5558 bytes examples/longtalk/static/style.css | 88 +++++++++++++++++++++++++ examples/longtalk/templates/base.html | 34 ++++++++++ examples/longtalk/templates/index.html | 21 ++++++ 5 files changed, 159 insertions(+) create mode 100644 examples/longtalk/app.py create mode 100644 examples/longtalk/static/favicon.ico create mode 100644 examples/longtalk/static/style.css create mode 100644 examples/longtalk/templates/base.html create mode 100644 examples/longtalk/templates/index.html diff --git a/examples/longtalk/app.py b/examples/longtalk/app.py new file mode 100644 index 00000000..e498b24b --- /dev/null +++ b/examples/longtalk/app.py @@ -0,0 +1,16 @@ +from jinja2.utils import generate_lorem_ipsum +from flask import Flask, jsonify, render_template + +app = Flask(__name__) +app.secret_key = os.getenv('SECRET_KEY', 'secret string') + + +@app.route('/') +def index(): + post_body = generate_lorem_ipsum(n=3) + return render_template('index.html', post_body=post_body) + + +@app.route('/more') +def load_post(): + return generate_lorem_ipsum(n=3) diff --git a/examples/longtalk/static/favicon.ico b/examples/longtalk/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..096f17960c5157d6194ab4f8f9d31f73e370ccd8 GIT binary patch literal 5558 zcmd^DTPSr~6kZ!eZf&{Ww@cb73ArnhL@2xxUYH!GJl61$<#)Az5BtCSZ?`kEFA+6KhCRR1}$+nITV4Pvqt0g{-Zuu^eF0 z-Q3(LJ~A?r^4PWJvt^`I&Teb(zG+#l=zl z$;k=X-`}Ucy}eDqcXoDYuBWHRBtAJgnbu@xW=d)-EiGxTx3^c4gRz6Br>E1J+}vDA zjh&qx%?%6;NOFkJ&d#Pa1qB6?8u$-_4G#}Xa){5%%cC_F6&1w7!s1_b9v&VvH$6Q~ z;93xaab#qK+}zyI8u*x>pJz3dm6ZhkJ7~AJx5V7s9P{+qv$wY=dcB^xm6a9diM6#g z>xUX!TU*Qlwn_A#d45Is*A3U1)87@_vyR!O!0&E z-~XY$MBCfjo0OE4nDm^S98=dq;Q3a<`uX{p#Ns`GXZ-#B9Ulovgn8cI-(QwzcXwA( z&vy(C4$9(C8>5$(7bz_*C6kkr3=VVT`T057+S(%V@$s@e@cbtxCX&|HR&sWBMzL@$ z@LV4r9xBc;sLe;5_kpOqyj)h3ujkvdv$ItH`ubWEj^_vu52qaP0dpUp`>egVxJa@0 z_xGA`Ja0@)4AZZws?x->w6sLA4-XHTaJ)YJmT1-0)tY$L*VifZ_4QQ~j@M61OG9~5 zTU)D%2i9gZGcz+ySR4bco4`|7SEq^N;NSq|W!FX2P>T8a`HVwpehnJ&!VupWH$(a})?dpzF9#>N;98UX(Ms6UO4;;J|RufOYKS7}b35?(SwhaG%v+ zpvKkJmEoWf78a%&%WL%Y^)a5QsVUVQu!rIe&Z#`F+V;@U5Tk)}u3B7RU?9Um!_h#@D6~_DYfDE<}EcfRW+99otv9uG<$n{ z#M9H0p0{*5ogyE+C*TeC#4au_s@6exM*;iC)zwwP&!IdY{|*Gl3+Ke5q9QUeF+umK zd_A_`-rk6fjg8{iH#Rn~++<8iNs(}5Wo4PH$HdCYiUfz_#|ZCg;60F%%iVuC7b{^P s2lEo@aPe23J3s1!_8;6>KIXss`=6pVoPmEA{rne>gFkw*UYD literal 0 HcmV?d00001 diff --git a/examples/longtalk/static/style.css b/examples/longtalk/static/style.css new file mode 100644 index 00000000..cc60d80c --- /dev/null +++ b/examples/longtalk/static/style.css @@ -0,0 +1,88 @@ +body { + margin: auto; + width: 750px; +} + +nav ul { + list-style-type: none; + margin: 0; + padding: 0; + overflow: hidden; + background-color: #333; +} + +nav li { + float: left; +} + +nav li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +nav li a:hover { + background-color: #111; +} + +main { + padding: 10px 20px; +} + +.alert { + position: relative; + padding: 0.75rem 1.25rem; + margin-bottom: 1rem; + border: 1px solid transparent; + border-radius: 0.25rem; + color: #004085; + background-color: #cce5ff; + border-color: #b8daff; +} + +.error { + color: #721c24; + background-color: #f8d7da; + border-color: #f5c6cb; +} + +.note { + padding: 5px 10px 10px; + border-left: solid 2px #bbb; + margin-bottom: 20px; +} + +.note form { + display: inline; +} + +.info { + color: grey; +} + +.btn { + font-family: Arial; + font-size: 12px; + padding: 5px 8px; + text-decoration: none; + cursor: pointer; + background-color: white; + color: black; + border: 1px solid #999999; +} + +.btn:hover { + text-decoration: none; + border: 1px solid black; +} + +footer { + font-size: 13px; + color: #888; + border-top: 1px solid #eee; + margin-top: 25px; + text-align: center; + padding: 20px; +} diff --git a/examples/longtalk/templates/base.html b/examples/longtalk/templates/base.html new file mode 100644 index 00000000..8bab5aac --- /dev/null +++ b/examples/longtalk/templates/base.html @@ -0,0 +1,34 @@ + + + + {% block head %} + + {% block title %}HelloFlask - AJAX Example{% endblock %} + + {% block styles %} + + {% endblock %} + {% endblock %} + + + +
+ {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} + {% block content %}{% endblock %} +
+ + + diff --git a/examples/longtalk/templates/index.html b/examples/longtalk/templates/index.html new file mode 100644 index 00000000..996e39e1 --- /dev/null +++ b/examples/longtalk/templates/index.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block content %} +

校长讲话

+
{{ post_body }}
+ + + +{% endblock %}