mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Fixed #22313 -- Removed 'u' prefixes from documentation
This commit is contained in:
parent
232181d1c5
commit
3a97f992fb
21 changed files with 179 additions and 177 deletions
|
@ -103,7 +103,7 @@ Access the :attr:`~Form.errors` attribute to get a dictionary of error
|
|||
messages::
|
||||
|
||||
>>> f.errors
|
||||
{'sender': [u'Enter a valid email address.'], 'subject': [u'This field is required.']}
|
||||
{'sender': ['Enter a valid email address.'], 'subject': ['This field is required.']}
|
||||
|
||||
In this dictionary, the keys are the field names, and the values are lists of
|
||||
Unicode strings representing the error messages. The error messages are stored
|
||||
|
@ -291,7 +291,7 @@ it, you can access the clean data via its ``cleaned_data`` attribute::
|
|||
>>> f.is_valid()
|
||||
True
|
||||
>>> f.cleaned_data
|
||||
{'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'}
|
||||
{'cc_myself': True, 'message': 'Hi there', 'sender': 'foo@example.com', 'subject': 'hello'}
|
||||
|
||||
Note that any text-based field -- such as ``CharField`` or ``EmailField`` --
|
||||
always cleans the input into a Unicode string. We'll cover the encoding
|
||||
|
@ -308,7 +308,7 @@ only the valid fields::
|
|||
>>> f.is_valid()
|
||||
False
|
||||
>>> f.cleaned_data
|
||||
{'cc_myself': True, 'message': u'Hi there'}
|
||||
{'cc_myself': True, 'message': 'Hi there'}
|
||||
|
||||
``cleaned_data`` will always *only* contain a key for fields defined in the
|
||||
``Form``, even if you pass extra data when you define the ``Form``. In this
|
||||
|
@ -326,7 +326,7 @@ but ``cleaned_data`` contains only the form's fields::
|
|||
>>> f.is_valid()
|
||||
True
|
||||
>>> f.cleaned_data # Doesn't contain extra_field_1, etc.
|
||||
{'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'}
|
||||
{'cc_myself': True, 'message': 'Hi there', 'sender': 'foo@example.com', 'subject': 'hello'}
|
||||
|
||||
When the ``Form`` is valid, ``cleaned_data`` will include a key and value for
|
||||
*all* its fields, even if the data didn't include a value for some optional
|
||||
|
@ -338,12 +338,12 @@ fields. In this example, the data dictionary doesn't include a value for the
|
|||
... first_name = CharField()
|
||||
... last_name = CharField()
|
||||
... nick_name = CharField(required=False)
|
||||
>>> data = {'first_name': u'John', 'last_name': u'Lennon'}
|
||||
>>> data = {'first_name': 'John', 'last_name': 'Lennon'}
|
||||
>>> f = OptionalPersonForm(data)
|
||||
>>> f.is_valid()
|
||||
True
|
||||
>>> f.cleaned_data
|
||||
{'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'}
|
||||
{'nick_name': '', 'first_name': 'John', 'last_name': 'Lennon'}
|
||||
|
||||
In this above example, the ``cleaned_data`` value for ``nick_name`` is set to an
|
||||
empty string, because ``nick_name`` is ``CharField``, and ``CharField``\s treat
|
||||
|
@ -428,7 +428,7 @@ containing one field::
|
|||
|
||||
>>> f = ContactForm()
|
||||
>>> f.as_p()
|
||||
u'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>'
|
||||
'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>'
|
||||
>>> print(f.as_p())
|
||||
<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
|
||||
<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
|
||||
|
@ -447,7 +447,7 @@ flexibility::
|
|||
|
||||
>>> f = ContactForm()
|
||||
>>> f.as_ul()
|
||||
u'<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>\n<li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" /></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>'
|
||||
'<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>\n<li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" /></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>'
|
||||
>>> print(f.as_ul())
|
||||
<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>
|
||||
<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>
|
||||
|
@ -465,7 +465,7 @@ it calls its ``as_table()`` method behind the scenes::
|
|||
|
||||
>>> f = ContactForm()
|
||||
>>> f.as_table()
|
||||
u'<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>'
|
||||
'<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>'
|
||||
>>> print(f.as_table())
|
||||
<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
|
||||
<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>
|
||||
|
@ -752,7 +752,7 @@ when printed::
|
|||
>>> print(f['message'])
|
||||
<input type="text" name="message" />
|
||||
>>> f['message'].errors
|
||||
[u'This field is required.']
|
||||
['This field is required.']
|
||||
>>> print(f['message'].errors)
|
||||
<ul class="errorlist"><li>This field is required.</li></ul>
|
||||
>>> f['subject'].errors
|
||||
|
|
|
@ -24,11 +24,11 @@ exception or returns the clean value::
|
|||
>>> from django import forms
|
||||
>>> f = forms.EmailField()
|
||||
>>> f.clean('foo@example.com')
|
||||
u'foo@example.com'
|
||||
'foo@example.com'
|
||||
>>> f.clean('invalid email address')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid email address.']
|
||||
ValidationError: ['Enter a valid email address.']
|
||||
|
||||
.. _core-field-arguments:
|
||||
|
||||
|
@ -51,40 +51,40 @@ an empty value -- either ``None`` or the empty string (``""``) -- then
|
|||
>>> from django import forms
|
||||
>>> f = forms.CharField()
|
||||
>>> f.clean('foo')
|
||||
u'foo'
|
||||
'foo'
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
ValidationError: ['This field is required.']
|
||||
>>> f.clean(None)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
ValidationError: ['This field is required.']
|
||||
>>> f.clean(' ')
|
||||
u' '
|
||||
' '
|
||||
>>> f.clean(0)
|
||||
u'0'
|
||||
'0'
|
||||
>>> f.clean(True)
|
||||
u'True'
|
||||
'True'
|
||||
>>> f.clean(False)
|
||||
u'False'
|
||||
'False'
|
||||
|
||||
To specify that a field is *not* required, pass ``required=False`` to the
|
||||
``Field`` constructor::
|
||||
|
||||
>>> f = forms.CharField(required=False)
|
||||
>>> f.clean('foo')
|
||||
u'foo'
|
||||
'foo'
|
||||
>>> f.clean('')
|
||||
u''
|
||||
''
|
||||
>>> f.clean(None)
|
||||
u''
|
||||
''
|
||||
>>> f.clean(0)
|
||||
u'0'
|
||||
'0'
|
||||
>>> f.clean(True)
|
||||
u'True'
|
||||
'True'
|
||||
>>> f.clean(False)
|
||||
u'False'
|
||||
'False'
|
||||
|
||||
If a ``Field`` has ``required=False`` and you pass ``clean()`` an empty value,
|
||||
then ``clean()`` will return a *normalized* empty value rather than raising
|
||||
|
@ -175,7 +175,7 @@ validation if a particular field's value is not given. ``initial`` values are
|
|||
False
|
||||
# The form does *not* fall back to using the initial values.
|
||||
>>> f.errors
|
||||
{'url': [u'This field is required.'], 'name': [u'This field is required.']}
|
||||
{'url': ['This field is required.'], 'name': ['This field is required.']}
|
||||
|
||||
Instead of a constant, you can also pass any callable::
|
||||
|
||||
|
@ -245,7 +245,7 @@ want to override. For example, here is the default error message::
|
|||
>>> generic.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
ValidationError: ['This field is required.']
|
||||
|
||||
And here is a custom error message::
|
||||
|
||||
|
@ -253,7 +253,7 @@ And here is a custom error message::
|
|||
>>> name.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Please enter your name']
|
||||
ValidationError: ['Please enter your name']
|
||||
|
||||
In the `built-in Field classes`_ section below, each ``Field`` defines the
|
||||
error message keys it uses.
|
||||
|
@ -867,11 +867,11 @@ Slightly complex built-in ``Field`` classes
|
|||
>>> from django.forms import ComboField
|
||||
>>> f = ComboField(fields=[CharField(max_length=20), EmailField()])
|
||||
>>> f.clean('test@example.com')
|
||||
u'test@example.com'
|
||||
'test@example.com'
|
||||
>>> f.clean('longemailaddress@example.com')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Ensure this value has at most 20 characters (it has 28).']
|
||||
ValidationError: ['Ensure this value has at most 20 characters (it has 28).']
|
||||
|
||||
``MultiValueField``
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -408,7 +408,7 @@ sample) looks like this::
|
|||
subject = cleaned_data.get("subject")
|
||||
|
||||
if cc_myself and subject and "help" not in subject:
|
||||
msg = u"Must put 'help' in subject when cc'ing yourself."
|
||||
msg = "Must put 'help' in subject when cc'ing yourself."
|
||||
self.add_error('cc_myself', msg)
|
||||
self.add_error('subject', msg)
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ foundation for custom widgets.
|
|||
>>> from django import forms
|
||||
>>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
|
||||
>>> name.render('name', 'A name')
|
||||
u'<input title="Your name" type="text" name="name" value="A name" size="10" />'
|
||||
'<input title="Your name" type="text" name="name" value="A name" size="10" />'
|
||||
|
||||
.. versionchanged:: 1.8
|
||||
|
||||
|
@ -342,7 +342,7 @@ foundation for custom widgets.
|
|||
return [None, None, None]
|
||||
|
||||
def format_output(self, rendered_widgets):
|
||||
return u''.join(rendered_widgets)
|
||||
return ''.join(rendered_widgets)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
datelist = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue