views:

91

answers:

3

I have a webpage that displays data based on a default date. The user can then change their view of the data by slecting a date with a date picker and clicking a submit button. I already have a variable set so that if no date is chosen, a default date is used.... so what's the problem? The problem comes if the user trys to type in the url page without a parameter... like so:

http://mywebpage/viewdata (example A)

instead of

http://mywebpage/viewdata?date= (example B)

I tried using:

if request.method == 'GET':

but apparently, even example A still returns true. I'm sure I'm doing some obvious beginner's mistake but I'll ask anyway... Is there a simpler way to handle example A other than passing the url to a string and checking the string for "?date="?

A: 

http://docs.djangoproject.com/en/dev/ref/request-response/

It sounds you are interested in POST

Unreason
No. POST is for making submissions that change data, or have other side-effects, not just for altering the view of that data.
Daniel Roseman
@Daniel, yes, but it sounded like he wants to make a distinction in between user clicking on the submit and the GET. Or maybe I didn't get it. Anyway the request-response docs have enough info on various scenarios.
Unreason
+1  A: 

I don't really understand your question - some more code would have helped - but don't you just need to do:

if 'date' in request.GET:
Daniel Roseman
Daniel Roseman... you the man! That is exactly what I needed! Thanks!
Mike
+1  A: 

You mentioned that you have default values defined somewhere.

Instead of doing something like this:

if 'date' in request.GET:
    date = request.GET['date']
else:
    date = '2010-05-04'

It's easier to do it this way:

date = request.GET.get('date', '2010-05-04')
Jusso