I have a question regarding Djanog views
here is a sample code
def example register ( request ) :
if request.method == ’POST ’ :
username = request.POST.get ( ’ username ’ )
password = request.POST.get ( ’ password ’ )
email = request.POST.get (’email’)
user = User.objects .create_user ( username
, email
, password )
user . save ()
return HttpResponseRedirect (
’/ example /login / ’)
In the above example we are taking the values one by one i.e username, password etc. If I have many such fields, then how can I do it in one single line, i was thinking to use dict's but can not find a way. Any help is appreciated. Thank you.
you should be using forms[1] and model-forms [2] to collect such data from the request.
[1] http://docs.djangoproject.com/en/dev/topics/forms/
[2] http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With