1๐
โ
-
Define a form; in forms.py under your appโs folder
class MyForm(forms.Form): myinput = forms.forms.CharField(max_length=100)
-
Define a function in your views.py
import .forms def handle_form(request): if request.method == 'POST': # If the form has been submitted... form = MyForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... return HttpResponseRedirect('/thanks/') # Redirect after POST else: form = MyForm() # An unbound form return render(request, 'handle_form.html', { 'form': form, })
-
Add a template
<form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Submit" /> </form>
Of course you need to add it to your urls.py
Most info was copy pasted from: https://docs.djangoproject.com/en/1.8/topics/forms/
๐คacidjunk
Source:stackexchange.com