Как сохранить значения из табличной формы в sqlite db через Python CGI? - PullRequest
0 голосов
/ 17 мая 2018

У меня есть таблица, как показано ниже:

<form action = "get.py" method = "get">
First Name: <input type = "text" name = "first_name">  <br />

Last Name: <input type = "text" name = "last_name" />
<input type = "submit" value = "Submit" />
</form>

Я пытался передать значение через Python CGI (Centos + Apache + CGI)

#!/usr/bin/python                                                         

# Import modules for CGI handling                                         
import cgi, cgitb                                                         

# Create instance of FieldStorage                                         
form = cgi.FieldStorage()                                                 

# Get data from fields                                                    
tt = form.getvalue('first_name')                                           
cc = form.getvalue('last_name')                                            

import sqlite3                                                            
conn = sqlite3.connect('personal.db')                                     
c = conn.cursor()                                                         
sql = "INSERT INTO PQ VALUES ('%s', '%s', Datetime('now'), '0')" % (tt, cc) 
c.execute(sql)                                                            
c.close()      

дБ, как показано ниже:

sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE PQ (Title TEXT, Description TEXT, Time TEXT, Deleted TEXT);
INSERT INTO PQ VALUES('biochem','how to do learning path','2018-05-16 03:55:54','')
COMMIT;
sqlite> .q

когда я пытался отправить данные, cgi возвращает такие ошибки, как:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Что мне нужно сделать, чтобы это исправить?Отсутствует ли какая-либо конфигурация?

...