python - Django: construct form without validating fields? -
I have a form myForm from request.POST and feeds it back.
def update_form (request)): if request.method == 'POST': dict = {} dict ['form'] = MyForm (request.POST) .as_p () return HttpResponse (Json.dumps (dict), mimetype = 'application / javascript') HttpResponseBadRequest () Return, however, this calls for cleaning / recognition routines, and I Do not want to show messages until they actually activate "submit".
So the question is: How do I create a django.forms.form with existing data?
Unless you call form.is_valid () Until then the verification does not start. But as I'm guessing, you want that the data in your form is filled with user type, as long as users do not submit clicks.
def update_form (request): if request.me Thod == 'POST': If request is not done. POST.get ('submit'): dict = {} dict ['form'] = MyForm (initial = dict (request.POST.items ())). HttpResponse (json.dumps (dict), mimetype = 'application / javascript') for return as_p () return: form = myForm (request.POST) if form.is_valid (): # return your final content HttpResponseBadRequest () Happy coding.
Comments
Post a Comment