Hello, WEB')
@app.route('/read//')
def read(id):
title = ''
body = ''
for topic in topics:
if id == topic['id']:
title = topic['title']
body = topic['body']
break
return template(getContents(), f'
{title}
{body}', id)
@app.route('/create/', methods=['GET', 'POST'])
def create():
if request.method == 'GET':
content = '''
'''
return template(getContents(), content)
elif request.method == 'POST':
global nextId
title = request.form['title']
body = request.form['body']
newTopic = {'id': nextId, 'title': title, 'body': body}
topics.append(newTopic)
url = '/read/'+str(nextId)+'/'
nextId = nextId + 1
return redirect(url)
@app.route('/update//', methods=['GET', 'POST'])
def update(id):
if request.method == 'GET':
title = ''
body = ''
for topic in topics:
if id == topic['id']:
title = topic['title']
body = topic['body']
break
content = f'''
'''
return template(getContents(), content)
elif request.method == 'POST':
global nextId
title = request.form['title']
body = request.form['body']
for topic in topics:
if id == topic['id']:
topic['title'] = title
topic['body'] = body
break
url = '/read/'+str(id)+'/'
return redirect(url)
@app.route('/delete//', methods=['POST'])
def delete(id):
for topic in topics:
if id == topic['id']:
topics.remove(topic)
break
return redirect('/')
app.run(debug=True)