# application/forms.py
from django import forms
class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
email = forms.EmailField()
message = forms.CharField(max_length=1000)
blog/views.py
def third(request):
return render(request,'third.html', {'name': request.method})
blog/urls.py
path('', views.index, name='index'),
path('second', views.second, name='index'),
path('hello', views.third, name='index')
blog/template/mypage.html
<form action="/blog/hello" method="POST">
{% csrf_token %}
<input type="submit" value="submit"/>
</form>
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import NameForm
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')
# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()
return render(request, 'name.html', {'form': form})
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
# Create your forms here.
class NameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
from django import forms
class FormName(forms.Form):
# each field would be mapped as an input field in HTML
field_name = forms.Field(**options)
# application/forms.py
from django import forms
class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
email = forms.EmailField()
message = forms.CharField(max_length=1000)
blog/views.py
def third(request):
return render(request,'third.html', {'name': request.method})
blog/urls.py
path('', views.index, name='index'),
path('second', views.second, name='index'),
path('hello', views.third, name='index')
blog/template/mypage.html
<form action="/blog/hello" method="POST">
{% csrf_token %}
<input type="submit" value="submit"/>
</form>
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import NameForm
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')
# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()
return render(request, 'name.html', {'form': form})
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
# Create your forms here.
class NameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
from django import forms
class FormName(forms.Form):
# each field would be mapped as an input field in HTML
field_name = forms.Field(**options)