[開発ログ22.03.31]

6075 ワード

学習の内容


データベースpythonバインド


from flask import Flask, request, redirect
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 ...."}
]
nextId = 4
def template(content, id=None):
liTags = ''
for topic in topics:
liTags = liTags + f'
  • {topic["title"]}
  • 'return f'''

    WEB


    {liTags}
    {content}
  • create

  • '''
    @app.route("/")
    def index():
    return template('

    Welcome

    Hello, WEB!')
    @app.route("/read//")
    def read(id):
    title = ''
    body = ''
    for topic in topics :
    if topic['id'] == id:
    title = topic['title']
    body = topic['body']
    break;
    return template(f'

    {title}

    {body}', id)
    @app.route('/create/')
    def create():
    content = '''
    <form action="/create_process/" method="POST">
      <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('/create_process/', methods=['POST'])
    def create_process():
    global nextId
    title = request.form['title']
    body = request.form['body']
    newTopic = {"id":nextId, "title": title, "body": body}
    topics.append(newTopic)
    nextId = nextId + 1
    return redirect(f'/read/{nextId-1}/')
    @app.route('/delete//', methods=['POST'])
    def delete(id):
    for topic in topics:
    if topic['id'] == id:
    topics.remove(topic)
    break;
    return redirect('/')
    //@app.route('/update/')
    //def update():
    // return 'Update'
    app.run()

    学習中の難点や難点


    めったにありません

    ソリューションの作成


    タスクをチェックした後の検索またはコメントページ

    学習の心得.


    前日よりは理解していたのですが、今まで、助けがなかったら一人でやるのは難しいかもしれません.