簡體   English   中英

如何使用cgi接受帶有python腳本的發布請求?

[英]How do I accept post requests with a python script using cgi?

我想將文本提交到HTML表單並將其發送到Python腳本。 當我按下提交按鈕時,它會轉到一個錯誤頁面,上面寫着:

錯誤代碼:501消息:不支持的方法('POST')。 錯誤代碼說明:HTTPStatus.NOT_IMPLEMENTED - 服務器不支持此操作。

我不確定問題是什么。 我已經搜索了錯誤消息並查看了不同的文檔並觀看了一些視頻,但它們似乎掩蓋了如何正確設置服務器。

我正在運行Python 3.7。

<form action="www/cgi-bin/hello.py" method="post">
First Name: 
<input type="text" name="first_name" placeholder="e.g. Barack" required="required"/>

Last Name: 
<input type="text" name="last_name" placeholder="e.g. Obama" required="required"/>

<input type="submit" name="submitprompt" value="Submit"/>
</form>
#!/usr/bin/python

import cgi, cgitb

first_name = form.getvalue('first_name')
last_name  = form.getvalue('last_name')
print("Content-type:text/html")
print("")
print("")
print("Hello - Second CGI Program")
print("")
print("")
print("   Hello %s %s" % (first_name, last_name))
print("")
print("")

我希望得到一個包含文本的頁面: Hello first_name last_name 相反,我收到上述錯誤。

使用命令“python3 -m http.server --cgi 8000”並從那里配置解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM