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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章