[개발일지 22.03.31]
학습한 내용
데이터베이스 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'
return f'''
WEB
{liTags}
{content}
'''
@app.route("/")
def index():
return template('
Welcome
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'
{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/<int:id>/', 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()
학습한 내용 중 어려웠던 점 또는 해결못한점
용어의 생소함
해결방법 작성
작업이후 검색 또는 치트시트 확인
학습 소감
전날에 비해서는 이해는 하게 되었지만 아직까진 도움없이 혼자하기에는 힘들것 같다
Author And Source
이 문제에 관하여([개발일지 22.03.31]), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dofoong/개발일지-22.03.31저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)