python - 如何通过python cgi将表形式的值保存到sqlite db中?
问题描述
我有一个如下表:
<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.
我应该怎么做才能解决这个问题?是否缺少任何配置?
解决方案
推荐阅读
- rest - 如何放心保留登录会话?
- javascript - angular 7 应用程序无法在 Firefox 中运行,但在 chrome 和 edge 中运行良好
- c# - 如何在 ASP.net MVC 中填充组合框选定项更改的详细信息字段
- c# - 在这种情况下如何检查链表是否有循环
- dependency-injection - requireBinding 有什么用?
- swift - 从另一个类为 Present ViewController Swift 调用特定函数
- android - 在方向更改期间保存 Recycler 视图的实例
- c# - 在 C# 的循环中使用 lambda 表达式启动任务
- c - SIGIO 什么时候开火?
- sql - 如何更改表