Question

I am doing web application and I cannot retrieve a date value from the browser. I have selected the date 01/16/2014.

The query string looks like:

?dd=01%2F16%2F2014

and my code is:

from django.http import HttpResponse, HttpResponseNotFound 
import cgi, cgitb 

form = cgi.FieldStorage()
def pod_available(request):
    dat = form.getvalue('dd')
    print dat
    return HttpResponse("<html><body>Hello<em>" + str(dat) + "</em></body></html>")

Output:

HelloNone
Was it helpful?

Solution 2

If this is a Django application, then using CGI in any way makes absolutely no sense. I assume that pod_available is being called with a HttpRequest object passed to it, so if you want to read the request data, you have to access that object to get it.

You can do that by accessing they key—'dd' in this case—of the object:

def pod_available(request):
    dat = request['dd']
    return HttpResponse("<html><body>Hello<em>" + str(dat) + "</em></body></html>")

In any way, this is not a CGI application, so don’t use any CGI stuff in there.

OTHER TIPS

If you are building a Django application, you are not using CGI. The forms variable will only be filled once, and will forever be empty. You may as well remove the cgi and cgitb module imports, they are of no use to you here.

You need to re-read the Django tutorial; the request parameter to your view contains all your form variables:

def pod_available(request):
    dat = request.GET['dd']
    print dat
    return HttpResponse("<html><body>Hello<em>" + str(dat) + "</em></body></html>")

The request.GET object is a dictionary holding the request parameters passed in via the URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top