Ruby CGI lib compare with Python CGI lib: Get form value

This is the Ruby  

require 'cgi'

dcgi=CGI.new

dcgi["name"]==dcgi.params["name"][0]

This is the Python
import 'cgi'
form = cgi.FieldStorage()
form["name"].value
But recommend use follow way:
form.getvalue("user", "")   #The second parameter is the default value if the value is not existent
form.getlist("user")
form.getfirst("user","")
都是用字典來存儲CGI參數, 只是語法上有所差異, 很接近的設計風格呢。。
發佈了26 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章