1 2 3 4 5 6 | def form_kwargs(request):
kwargs = {}
if request.method == 'POST':
kwargs['data'] = request.POST
kwargs['files'] = request.FILES
return kwargs
|
More like this
- Gzip decorator by SmileyChris 4 years, 9 months ago
- newforms field callback helper by SmileyChris 6 years ago
- Allow separation of GET and POST implementations by agore 11 months, 1 week ago
- Honeypot Field by SmileyChris 6 years, 1 month ago
- LoginAsForm - Login as any User without a password by johnboxall 3 years, 11 months ago
Comments
Maybe its just me, but I don't see how this is "DRY"er. Not even sure what the point of it is.
#
Normally, you'd write:
Now you write:
#
PS: if you'd rather not bother with a helper like this, the method of instanciating a form only once for both cases is still useful.
The most simple case is (where files aren't involved and you always expect at least one thing in your POST):
#