Opened 11 years ago

Closed 11 years ago

#20563 closed New feature (wontfix)

Add validation in QueryDict.get()

Reported by: CHI Cheng Owned by: nobody
Component: HTTP handling Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Hi,

I'd like to suggest a new parameter in QueryDict.get() named pattern.

p = request.GET.get(key='q', default='10', pattern=r'^\d+$')

As it is submitted by user, the value of parameter q could be any characters. But I only need a non-negative number, so I add a new pattern parameter for QueryDict.get(), if the value does not match the pattern, then get() will return default value, as '10' in example, but not the value submitted by user.

If you love this tiny feature I could prepare a patch. (I think it only requires less than 10 lines of codes and dozens of lines of test codes?)

Change History (1)

comment:1 by Tim Graham, 11 years ago

Resolution: wontfix
Status: newclosed

Thank-you for the suggestion, however, I don't think this type of logic/validation should be part of QueryDict (it seems like something you may want to use the forms abstraction for).

Note: See TracTickets for help on using tickets.
Back to Top