Skip to content

Commit

Permalink
form
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Mar 15, 2018
1 parent 1afa66f commit 6f0d532
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions create.py
@@ -0,0 +1,37 @@
#!/usr/local/bin/python3
print("Content-Type: text/html")
print()
import cgi, os

files = os.listdir('data')
listStr = ''
for item in files:
listStr = listStr + '<li><a href="index.py?id={name}">{name}</a></li>'.format(name=item)

form = cgi.FieldStorage()
if 'id' in form:
pageId = form["id"].value
description = open('data/'+pageId, 'r').read()
else:
pageId = 'Welcome'
description = 'Hello, web'
print('''<!doctype html>
<html>
<head>
<title>WEB1 - Welcome</title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="index.py">WEB</a></h1>
<ol>
{listStr}
</ol>
<a href="create.py">create</a>
<form action="process_create.py" method="post">
<p><input type="text" name="title" placeholder="title"></p>
<p><textarea rows="4" name="description" placeholder="description"></textarea></p>
<p><input type="submit"></p>
</form>
</body>
</html>
'''.format(title=pageId, desc=description, listStr=listStr))
3 changes: 2 additions & 1 deletion index.py
Expand Up @@ -7,7 +7,7 @@
listStr = ''
for item in files:
listStr = listStr + '<li><a href="index.py?id={name}">{name}</a></li>'.format(name=item)

form = cgi.FieldStorage()
if 'id' in form:
pageId = form["id"].value
Expand All @@ -26,6 +26,7 @@
<ol>
{listStr}
</ol>
<a href="create.py">create</a>
<h2>{title}</h2>
<p>{desc}</p>
</body>
Expand Down

0 comments on commit 6f0d532

Please sign in to comment.