django - how can I return the post data to the manual html in a view -
I have a form.py file with form data and some assumptions, but in my template file, Do not present it using form.py after posting the template with the template, when I do not validate the data, how can I return the data to the template (valid in form.py). .
Sorry, my question is not so clear, my question is how can I send data back to the manual template in view.py after errors.
The following code is an example:
form.py (many fields in my form and some assumptions)
class Project_f (forms.Form ): Slug = forms.CharField (max_length = 100) ...... views.py
def post_view (requests, * args, ** kwargs): Pr_form = Project_f (Request post, request.FILES) if Pr_form.is_valid (): ......... Return HTTPPRPS portal ('/ admin / MPM / project /') '' 'when Pro_form is not valid '' 'c = {' form ': Pr_form} c.update (csrf (request)) Manu again without using Form.py A template template
, all elements are the same with form.py, but the format / widget is different, such as with some JS < / Div>
Just because you have not sent form objects in the template, you can still validate against the data. Whatever you are submitting, you need to check the request. POST then my old farm = myForm (Data = Request.POST) has been done by my farm.is_widid (). Just make sure that your respected "Name" element in the form you created in HTML has been set to you in your Form Class. preform class MyForm (forms.Form): foo = forms.CharField () bar = forms.CharField () def myView (request): if request.POST: myForm = myForm (data = request POST) if myForm.is_valid (): "" "stuff" "other:" "" stuff with errors "" other: "" "print a page or something" < / Pre>
Comments
Post a Comment