mirror of
https://github.com/django/django.git
synced 2025-01-26 02:00:08 +00:00
[1.8.x] Specified file names for example code in docs/topics/forms/index.txt
Backport of f9c212d09ad59cd5b5d9be06e92be87d44c75d95 from master
This commit is contained in:
parent
9f632dc702
commit
b3d36c3514
@ -224,7 +224,10 @@ The :class:`Form` class
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
We already know what we want our HTML form to look like. Our starting point for
|
We already know what we want our HTML form to look like. Our starting point for
|
||||||
it in Django is this::
|
it in Django is this:
|
||||||
|
|
||||||
|
.. snippet::
|
||||||
|
:filename: forms.py
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
@ -271,11 +274,16 @@ same view which published the form. This allows us to reuse some of the same
|
|||||||
logic.
|
logic.
|
||||||
|
|
||||||
To handle the form we need to instantiate it in the view for the URL where we
|
To handle the form we need to instantiate it in the view for the URL where we
|
||||||
want it to be published::
|
want it to be published:
|
||||||
|
|
||||||
|
.. snippet::
|
||||||
|
:filename: views.py
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
|
from .forms import NameForm
|
||||||
|
|
||||||
def get_name(request):
|
def get_name(request):
|
||||||
# if this is a POST request we need to process the form data
|
# if this is a POST request we need to process the form data
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -392,7 +400,10 @@ More on fields
|
|||||||
--------------
|
--------------
|
||||||
|
|
||||||
Consider a more useful form than our minimal example above, which we could use
|
Consider a more useful form than our minimal example above, which we could use
|
||||||
to implement "contact me" functionality on a personal Web site::
|
to implement "contact me" functionality on a personal Web site:
|
||||||
|
|
||||||
|
.. snippet::
|
||||||
|
:filename: forms.py
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
@ -438,7 +449,10 @@ In the contact form example above, ``cc_myself`` will be a boolean value.
|
|||||||
Likewise, fields such as :class:`IntegerField` and :class:`FloatField` convert
|
Likewise, fields such as :class:`IntegerField` and :class:`FloatField` convert
|
||||||
values to a Python ``int`` and ``float`` respectively.
|
values to a Python ``int`` and ``float`` respectively.
|
||||||
|
|
||||||
Here's how the form data could be processed in the view that handles this form::
|
Here's how the form data could be processed in the view that handles this form:
|
||||||
|
|
||||||
|
.. snippet::
|
||||||
|
:filename: views.py
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user