現在掲示板を作ろうと思っています。
現在は書き込み、だけができる仮のものを作っているのですが、スレッド作成などはテーブルを新しくつくればいいのでしょうか。一般的にどんな構造なのか教えてほしいです。
html
1<!doctype html> 2<head> 3<title>掲示板</title> 4</head> 5<body> 6<h1>つぶやく</h1><hr> 7<form name="Form" method="POST" action="./show.py"> 8name: <input type="text" size="30" name="name"> 9mail: <input type="text" size="30" name="mail"><br> 10message: <input type="text" size="100" name="message"><br> 11<input type="submit" value="submit" name="button"> 12</form> 13</body> 14</html>
python
1#!C:\Python34\python.exe 2# -*- coding: utf-8 -*- 3import pymysql 4import cgi, sys, io 5from datetime import datetime 6 7class MainSys: 8 9 f = cgi.FieldStorage() 10 11 def __init__(self, *rec): 12 self._connection = None 13 self._cursor = None 14 self._name = MainSys.f.getfirst(rec[0], '') 15 self._mail = MainSys.f.getfirst(rec[1], '') 16 self._message = MainSys.f.getfirst(rec[2], '') 17 18 @property 19 def Name(self): 20 return self._name 21 22 @property 23 def Mail(self): 24 return self._mail 25 26 @property 27 def Message(self): 28 return self._message 29 30 31 def set_con(self, *con): 32 self._connection = pymysql.connect(host=con[0], 33 user=con[1], 34 password=con[2], 35 db=con[3], 36 charset=con[4]); 37 self._cursor = self._connection.cursor() 38 39 40 def read_db(self, sql): 41 self._cursor.execute(sql) 42 for r in self._cursor.fetchall(): 43 yield r 44 45 46 def write_db(self, sql, *rec): 47 self._cursor.execute(sql, (rec[0], rec[1], rec[2])) 48 self._connection.commit() 49 50 51 def close_db(self): 52 self._cursor.close() 53 self._connection.close()
python
1#!C:\Python34\python.exe 2# -*- coding: utf-8 -*- 3import cgi, sys, io 4from system.main_sys import MainSys 5 6sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') 7print('Content-Type: text/html\n') 8print('<!doctype html>\n<body>') 9 10s = MainSys('name', 'mail', 'message') 11s.set_con('localhost', 'root', 'pass', 'keiziban', 'utf8') 12 13def show(): 14 for wd in iter(s.read_db('select name, mail, message from keiziban.usershow')): 15 for inwd in wd: 16 print('<p>', inwd, '</p>') 17 print('<hr>') 18 19 20if s.Name != '' and s.Mail != '' and s.Message != '': 21 s.write_db('insert into usershow (name, mail, message) values (%s, %s, %s)', s.Name, s.Mail, s.Message) 22 show() 23else: 24 show() 25s.close_db() 26 27print('</body>\n</html>')
とりあえずはこんな感じで書いているのですが、これからどのようにしていけばいいのでしょうか
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。