python - Django - A bit lost with forms -
I am working in Django forms. Where do I place the code (forms.py/ or models.py?) About the form and what code I put in my template I searched about docs but it does not understand, I'm new to the Django Thank you.
I appreciate that someone can give me a complete example of a simple form to understand this stuff.
Thank you.
from
You must make the Django import forms by contact form form (forms. Forms your form class in forms.py
example
: subject = forms.CharField (Max_length = 100) message = forms. In order to render the form in your template, you must add the reference to your Views.py should look something like this. Submit from Django.shortcuts import to django.http.httpResponseRedirect def (request): If request.method == 'POST': # If the form is submitted ... # Contact form Previous section form = Configure form (request. POST) was defined in # form form.is_valid (): # Process data in all validation passes pass # form.cleaned_data # ... Back HTTPPREPSPoint Redirect ('/ thanks /') #Redirect after posting Other: Form = contact form () # one unbound Submit form return (request, 'contact.html', {'Form': form,}) Note this part. Dictionary {'form': form} is your request reference, which means that the keys in your template variables will be added.
return render (request, 'contact.html', 'form now you can use it in your template.
Comments
Post a Comment