Skip to content

Commit

Permalink
7.2 쓰기
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Mar 27, 2022
1 parent 6798a26 commit 9f77a02
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions server.py
@@ -1,8 +1,9 @@
from flask import Flask
from flask import Flask, request, redirect

app = Flask(__name__)


nextId = 4
topics = [
{'id': 1, 'title': 'html', 'body': 'html is ...'},
{'id': 2, 'title': 'css', 'body': 'css is ...'},
Expand Down Expand Up @@ -51,16 +52,26 @@ def read(id):
return template(getContents(), f'<h2>{title}</h2>{body}')


@app.route('/create/')
@app.route('/create/', methods=['GET', 'POST'])
def create():
content = '''
<form action="/create/" 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(getContents(), content)
if request.method == 'GET':
content = '''
<form action="/create/" 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(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.run(debug=True)

0 comments on commit 9f77a02

Please sign in to comment.