[共通トレーニング-Phythonの基礎知識]Flask
10821 ワード
1.勉強の内容
① Web Browser ↔ Application Server

② Flask
https://flask.palletsprojects.com





https://flask.palletsprojects.com/en/2.1.x/quickstart/#routing

from flask import Flask
app = Flask(__name__)
topics = [
{"id":1, "title":"html", "body":"html is ...."},
{"id":2, "title":"css", "body":"css is ...."},
{"id":3, "title":"js", "body":"js is ...."}
]
def template(content):
liTags = ''
for topic in topics:
liTags = liTags + f'<li><a href="/read/{topic["id"]}/">{topic["title"]}</a></li>'
return f'''
<html>
<body>
<h1><a href="/">WEB</a></h1>
<ol>
{liTags}
</ol>
{content}
<ul>
<li><a href="/create/">create</a></li>
</ul>
</body>
</html>
'''
@app.route("/")
def index():
return template('<h2>Welcome</h2>Hello, WEB!')
@app.route("/read/<int:id>/")
def read(id):
title = ''
body = ''
for topic in topics :
if topic['id'] == id:
title = topic['title']
body = topic['body']
break;
return template(f'<h2>{title}</h2>{body}')
@app.route('/create/')
def create():
content = '''
<form action="/create/">
<p><input type="text" name="title" placeholder="title"></p>
<p><textarea name="body" placeholder="body"></textarea></p>
<p><input type="submit" value="create"></p>
</form>
'''
return template(content)
@app.route('/update/')
def update():
return 'Update'
app.run()
③ Glitch
https://glitch.com










2.学習内容の難点
3.解決方法
4.勉強の心得
この有名な生活コード師の講義内容を聞くことができて光栄です.
Reference
この問題について([共通トレーニング-Phythonの基礎知識]Flask), 我々は、より多くの情報をここで見つけました https://velog.io/@s2angji/공통교육-파이썬-기초-Flaskテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol