Similar to this, but the solution there won’t work for me.
Basically, I’m trying to do this:
if request.method == 'POST':
profile_form = UserProfileForm(request.POST)
# ...
else:
profile_form = UserProfileForm(request.GET)
But then the form gets validated on a GET. Using initial=request.GET instead doesn’t work either because each of the entries is a list rather than a string. i.e., if I try to go to myform?company=mycompany the mycompany field gets set to [u'mycompany'].
Is there a different way to bypass validation, or is there an easy way to convert a querydict into regular dict (without the lists)?
You could turn
request.GETinto a dictionary with values that aren’t lists like so:That will grab the first item in each list, which means it will only work if all your inputs have different names (which they should or you’re not doing something right). Let me know if it works.
You may not need the
dict(request.GET).items(), you may be able to just putrequest.GET.items().