Fixed #26021 -- Applied hanging indentation to docs.
This commit is contained in:
parent
38575b007a
commit
4a4d7f980e
|
@ -106,11 +106,13 @@ options can be added in the :meth:`~BaseCommand.add_arguments` method like this:
|
||||||
parser.add_argument('poll_id', nargs='+', type=int)
|
parser.add_argument('poll_id', nargs='+', type=int)
|
||||||
|
|
||||||
# Named (optional) arguments
|
# Named (optional) arguments
|
||||||
parser.add_argument('--delete',
|
parser.add_argument(
|
||||||
|
'--delete',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='delete',
|
dest='delete',
|
||||||
default=False,
|
default=False,
|
||||||
help='Delete poll instead of closing it')
|
help='Delete poll instead of closing it',
|
||||||
|
)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# ...
|
# ...
|
||||||
|
|
|
@ -202,10 +202,12 @@ filtered out of error reports in a production environment (that is, where
|
||||||
|
|
||||||
@sensitive_post_parameters('pass_word', 'credit_card_number')
|
@sensitive_post_parameters('pass_word', 'credit_card_number')
|
||||||
def record_user_profile(request):
|
def record_user_profile(request):
|
||||||
UserProfile.create(user=request.user,
|
UserProfile.create(
|
||||||
|
user=request.user,
|
||||||
password=request.POST['pass_word'],
|
password=request.POST['pass_word'],
|
||||||
credit_card=request.POST['credit_card_number'],
|
credit_card=request.POST['credit_card_number'],
|
||||||
name=request.POST['name'])
|
name=request.POST['name'],
|
||||||
|
)
|
||||||
...
|
...
|
||||||
|
|
||||||
In the above example, the values for the ``pass_word`` and
|
In the above example, the values for the ``pass_word`` and
|
||||||
|
|
|
@ -104,9 +104,9 @@ Here's how this might look in a fabfile::
|
||||||
def deploy_static():
|
def deploy_static():
|
||||||
local('./manage.py collectstatic')
|
local('./manage.py collectstatic')
|
||||||
project.rsync_project(
|
project.rsync_project(
|
||||||
remote_dir = env.remote_static_root,
|
remote_dir=env.remote_static_root,
|
||||||
local_dir = env.local_static_root,
|
local_dir=env.local_static_root,
|
||||||
delete = True
|
delete=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
.. _staticfiles-from-cdn:
|
.. _staticfiles-from-cdn:
|
||||||
|
|
|
@ -462,8 +462,7 @@ class:
|
||||||
in the past, positive for questions that have yet to be published).
|
in the past, positive for questions that have yet to be published).
|
||||||
"""
|
"""
|
||||||
time = timezone.now() + datetime.timedelta(days=days)
|
time = timezone.now() + datetime.timedelta(days=days)
|
||||||
return Question.objects.create(question_text=question_text,
|
return Question.objects.create(question_text=question_text, pub_date=time)
|
||||||
pub_date=time)
|
|
||||||
|
|
||||||
|
|
||||||
class QuestionViewTests(TestCase):
|
class QuestionViewTests(TestCase):
|
||||||
|
@ -495,8 +494,7 @@ class:
|
||||||
"""
|
"""
|
||||||
create_question(question_text="Future question.", days=30)
|
create_question(question_text="Future question.", days=30)
|
||||||
response = self.client.get(reverse('polls:index'))
|
response = self.client.get(reverse('polls:index'))
|
||||||
self.assertContains(response, "No polls are available.",
|
self.assertContains(response, "No polls are available.")
|
||||||
status_code=200)
|
|
||||||
self.assertQuerysetEqual(response.context['latest_question_list'], [])
|
self.assertQuerysetEqual(response.context['latest_question_list'], [])
|
||||||
|
|
||||||
def test_index_view_with_future_question_and_past_question(self):
|
def test_index_view_with_future_question_and_past_question(self):
|
||||||
|
@ -580,10 +578,9 @@ in the future is not:
|
||||||
The detail view of a question with a pub_date in the future should
|
The detail view of a question with a pub_date in the future should
|
||||||
return a 404 not found.
|
return a 404 not found.
|
||||||
"""
|
"""
|
||||||
future_question = create_question(question_text='Future question.',
|
future_question = create_question(question_text='Future question.', days=5)
|
||||||
days=5)
|
url = reverse('polls:detail', args=(future_question.id,))
|
||||||
response = self.client.get(reverse('polls:detail',
|
response = self.client.get(url)
|
||||||
args=(future_question.id,)))
|
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
def test_detail_view_with_a_past_question(self):
|
def test_detail_view_with_a_past_question(self):
|
||||||
|
@ -591,13 +588,10 @@ in the future is not:
|
||||||
The detail view of a question with a pub_date in the past should
|
The detail view of a question with a pub_date in the past should
|
||||||
display the question's text.
|
display the question's text.
|
||||||
"""
|
"""
|
||||||
past_question = create_question(question_text='Past Question.',
|
past_question = create_question(question_text='Past Question.', days=-5)
|
||||||
days=-5)
|
url = reverse('polls:detail', args=(past_question.id,))
|
||||||
response = self.client.get(reverse('polls:detail',
|
response = self.client.get(url)
|
||||||
args=(past_question.id,)))
|
self.assertContains(response, past_question.question_text)
|
||||||
self.assertContains(response, past_question.question_text,
|
|
||||||
status_code=200)
|
|
||||||
|
|
||||||
|
|
||||||
Ideas for more tests
|
Ideas for more tests
|
||||||
--------------------
|
--------------------
|
||||||
|
|
|
@ -615,10 +615,12 @@ subclass::
|
||||||
color_code = models.CharField(max_length=6)
|
color_code = models.CharField(max_length=6)
|
||||||
|
|
||||||
def colored_name(self):
|
def colored_name(self):
|
||||||
return format_html('<span style="color: #{};">{} {}</span>',
|
return format_html(
|
||||||
|
'<span style="color: #{};">{} {}</span>',
|
||||||
self.color_code,
|
self.color_code,
|
||||||
self.first_name,
|
self.first_name,
|
||||||
self.last_name)
|
self.last_name,
|
||||||
|
)
|
||||||
|
|
||||||
class PersonAdmin(admin.ModelAdmin):
|
class PersonAdmin(admin.ModelAdmin):
|
||||||
list_display = ('first_name', 'last_name', 'colored_name')
|
list_display = ('first_name', 'last_name', 'colored_name')
|
||||||
|
@ -700,9 +702,11 @@ subclass::
|
||||||
color_code = models.CharField(max_length=6)
|
color_code = models.CharField(max_length=6)
|
||||||
|
|
||||||
def colored_first_name(self):
|
def colored_first_name(self):
|
||||||
return format_html('<span style="color: #{};">{}</span>',
|
return format_html(
|
||||||
|
'<span style="color: #{};">{}</span>',
|
||||||
self.color_code,
|
self.color_code,
|
||||||
self.first_name)
|
self.first_name,
|
||||||
|
)
|
||||||
|
|
||||||
colored_first_name.admin_order_field = 'first_name'
|
colored_first_name.admin_order_field = 'first_name'
|
||||||
|
|
||||||
|
@ -906,13 +910,11 @@ subclass::
|
||||||
|
|
||||||
def lookups(self, request, model_admin):
|
def lookups(self, request, model_admin):
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
return super(AuthDecadeBornListFilter,
|
return super(AuthDecadeBornListFilter, self).lookups(request, model_admin)
|
||||||
self).lookups(request, model_admin)
|
|
||||||
|
|
||||||
def queryset(self, request, queryset):
|
def queryset(self, request, queryset):
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
return super(AuthDecadeBornListFilter,
|
return super(AuthDecadeBornListFilter, self).queryset(request, queryset)
|
||||||
self).queryset(request, queryset)
|
|
||||||
|
|
||||||
Also as a convenience, the ``ModelAdmin`` object is passed to
|
Also as a convenience, the ``ModelAdmin`` object is passed to
|
||||||
the ``lookups`` method, for example if you want to base the
|
the ``lookups`` method, for example if you want to base the
|
||||||
|
@ -1268,8 +1270,8 @@ subclass::
|
||||||
|
|
||||||
class PersonAdmin(admin.ModelAdmin):
|
class PersonAdmin(admin.ModelAdmin):
|
||||||
def view_on_site(self, obj):
|
def view_on_site(self, obj):
|
||||||
return 'https://example.com' + reverse('person-detail',
|
url = reverse('person-detail', kwargs={'slug': obj.slug})
|
||||||
kwargs={'slug': obj.slug})
|
return 'https://example.com' + url
|
||||||
|
|
||||||
Custom template options
|
Custom template options
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -1875,8 +1877,9 @@ provided some extra mapping data that would not otherwise be available::
|
||||||
def change_view(self, request, object_id, form_url='', extra_context=None):
|
def change_view(self, request, object_id, form_url='', extra_context=None):
|
||||||
extra_context = extra_context or {}
|
extra_context = extra_context or {}
|
||||||
extra_context['osm_data'] = self.get_osm_info()
|
extra_context['osm_data'] = self.get_osm_info()
|
||||||
return super(MyModelAdmin, self).change_view(request, object_id,
|
return super(MyModelAdmin, self).change_view(
|
||||||
form_url, extra_context=extra_context)
|
request, object_id, form_url, extra_context=extra_context,
|
||||||
|
)
|
||||||
|
|
||||||
These views return :class:`~django.template.response.TemplateResponse`
|
These views return :class:`~django.template.response.TemplateResponse`
|
||||||
instances which allow you to easily customize the response data before
|
instances which allow you to easily customize the response data before
|
||||||
|
|
|
@ -120,7 +120,7 @@ raster models::
|
||||||
|
|
||||||
>>> from django.contrib.gis.gdal import GDALRaster
|
>>> from django.contrib.gis.gdal import GDALRaster
|
||||||
>>> rast = GDALRaster({'width': 10, 'height': 10, 'name': 'Canyon', 'srid': 4326,
|
>>> rast = GDALRaster({'width': 10, 'height': 10, 'name': 'Canyon', 'srid': 4326,
|
||||||
... 'scale': [0.1, -0.1]'bands': [{"data": range(100)}]}
|
... 'scale': [0.1, -0.1], 'bands': [{"data": range(100)}]})
|
||||||
>>> dem = Elevation(name='Canyon', rast=rast)
|
>>> dem = Elevation(name='Canyon', rast=rast)
|
||||||
>>> dem.save()
|
>>> dem.save()
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ Note that this equivalent to::
|
||||||
>>> dem = Elevation.objects.create(
|
>>> dem = Elevation.objects.create(
|
||||||
... name='Canyon',
|
... name='Canyon',
|
||||||
... rast={'width': 10, 'height': 10, 'name': 'Canyon', 'srid': 4326,
|
... rast={'width': 10, 'height': 10, 'name': 'Canyon', 'srid': 4326,
|
||||||
... 'scale': [0.1, -0.1]'bands': [{"data": range(100)}]}
|
... 'scale': [0.1, -0.1], 'bands': [{"data": range(100)}]},
|
||||||
... )
|
... )
|
||||||
|
|
||||||
.. _spatial-lookups-intro:
|
.. _spatial-lookups-intro:
|
||||||
|
|
|
@ -452,12 +452,15 @@ with the following code::
|
||||||
'mpoly' : 'MULTIPOLYGON',
|
'mpoly' : 'MULTIPOLYGON',
|
||||||
}
|
}
|
||||||
|
|
||||||
world_shp = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'TM_WORLD_BORDERS-0.3.shp'))
|
world_shp = os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(__file__), 'data', 'TM_WORLD_BORDERS-0.3.shp'),
|
||||||
|
)
|
||||||
|
|
||||||
def run(verbose=True):
|
def run(verbose=True):
|
||||||
lm = LayerMapping(WorldBorder, world_shp, world_mapping,
|
lm = LayerMapping(
|
||||||
transform=False, encoding='iso-8859-1')
|
WorldBorder, world_shp, world_mapping,
|
||||||
|
transform=False, encoding='iso-8859-1',
|
||||||
|
)
|
||||||
lm.save(strict=True, verbose=verbose)
|
lm.save(strict=True, verbose=verbose)
|
||||||
|
|
||||||
A few notes about what's going on:
|
A few notes about what's going on:
|
||||||
|
|
|
@ -320,8 +320,7 @@ Adding extra message tags
|
||||||
For more direct control over message tags, you can optionally provide a string
|
For more direct control over message tags, you can optionally provide a string
|
||||||
containing extra tags to any of the add methods::
|
containing extra tags to any of the add methods::
|
||||||
|
|
||||||
messages.add_message(request, messages.INFO, 'Over 9000!',
|
messages.add_message(request, messages.INFO, 'Over 9000!', extra_tags='dragonball')
|
||||||
extra_tags='dragonball')
|
|
||||||
messages.error(request, 'Email box full', extra_tags='email')
|
messages.error(request, 'Email box full', extra_tags='email')
|
||||||
|
|
||||||
Extra tags are added before the default tag for that level and are space
|
Extra tags are added before the default tag for that level and are space
|
||||||
|
@ -336,8 +335,10 @@ if they don't want to, you may pass an additional keyword argument
|
||||||
``fail_silently=True`` to any of the ``add_message`` family of methods. For
|
``fail_silently=True`` to any of the ``add_message`` family of methods. For
|
||||||
example::
|
example::
|
||||||
|
|
||||||
messages.add_message(request, messages.SUCCESS, 'Profile details updated.',
|
messages.add_message(
|
||||||
fail_silently=True)
|
request, messages.SUCCESS, 'Profile details updated.',
|
||||||
|
fail_silently=True,
|
||||||
|
)
|
||||||
messages.info(request, 'Hello world.', fail_silently=True)
|
messages.info(request, 'Hello world.', fail_silently=True)
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
|
@ -197,10 +197,14 @@ Here's an example of what the form-handling view looks like::
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
current_site = get_current_site(request)
|
current_site = get_current_site(request)
|
||||||
send_mail('Thanks for subscribing to %s alerts' % current_site.name,
|
send_mail(
|
||||||
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' % current_site.name,
|
'Thanks for subscribing to %s alerts' % current_site.name,
|
||||||
|
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' % (
|
||||||
|
current_site.name,
|
||||||
|
),
|
||||||
'editor@%s' % current_site.domain,
|
'editor@%s' % current_site.domain,
|
||||||
[user.email])
|
[user.email],
|
||||||
|
)
|
||||||
|
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
|
|
|
@ -998,16 +998,25 @@ Slightly complex built-in ``Field`` classes
|
||||||
}
|
}
|
||||||
# Or define a different message for each field.
|
# Or define a different message for each field.
|
||||||
fields = (
|
fields = (
|
||||||
CharField(error_messages={'incomplete': 'Enter a country calling code.'},
|
CharField(
|
||||||
validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid country calling code.')]),
|
error_messages={'incomplete': 'Enter a country calling code.'},
|
||||||
CharField(error_messages={'incomplete': 'Enter a phone number.'},
|
validators=[
|
||||||
validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid phone number.')]),
|
RegexValidator(r'^[0-9]+$', 'Enter a valid country calling code.'),
|
||||||
CharField(validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid extension.')],
|
],
|
||||||
required=False),
|
),
|
||||||
|
CharField(
|
||||||
|
error_messages={'incomplete': 'Enter a phone number.'},
|
||||||
|
validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid phone number.')],
|
||||||
|
),
|
||||||
|
CharField(
|
||||||
|
validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid extension.')],
|
||||||
|
required=False,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
super(PhoneField, self).__init__(
|
super(PhoneField, self).__init__(
|
||||||
error_messages=error_messages, fields=fields,
|
error_messages=error_messages, fields=fields,
|
||||||
require_all_fields=False, *args, **kwargs)
|
require_all_fields=False, *args, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
.. attribute:: MultiValueField.widget
|
.. attribute:: MultiValueField.widget
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,11 @@ widget on the field. In the following example, the
|
||||||
|
|
||||||
class SimpleForm(forms.Form):
|
class SimpleForm(forms.Form):
|
||||||
birth_year = forms.DateField(widget=forms.SelectDateWidget(years=BIRTH_YEAR_CHOICES))
|
birth_year = forms.DateField(widget=forms.SelectDateWidget(years=BIRTH_YEAR_CHOICES))
|
||||||
favorite_colors = forms.MultipleChoiceField(required=False,
|
favorite_colors = forms.MultipleChoiceField(
|
||||||
widget=forms.CheckboxSelectMultiple, choices=FAVORITE_COLORS_CHOICES)
|
required=False,
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
choices=FAVORITE_COLORS_CHOICES,
|
||||||
|
)
|
||||||
|
|
||||||
See the :ref:`built-in widgets` for more information about which widgets
|
See the :ref:`built-in widgets` for more information about which widgets
|
||||||
are available and which arguments they accept.
|
are available and which arguments they accept.
|
||||||
|
|
|
@ -371,7 +371,8 @@ SQL that is generated. Here's a brief example::
|
||||||
expression,
|
expression,
|
||||||
distinct='DISTINCT ' if distinct else '',
|
distinct='DISTINCT ' if distinct else '',
|
||||||
output_field=IntegerField(),
|
output_field=IntegerField(),
|
||||||
**extra)
|
**extra
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
``Value()`` expressions
|
``Value()`` expressions
|
||||||
|
|
|
@ -112,9 +112,11 @@ define a suitably-named constant for each value::
|
||||||
(JUNIOR, 'Junior'),
|
(JUNIOR, 'Junior'),
|
||||||
(SENIOR, 'Senior'),
|
(SENIOR, 'Senior'),
|
||||||
)
|
)
|
||||||
year_in_school = models.CharField(max_length=2,
|
year_in_school = models.CharField(
|
||||||
|
max_length=2,
|
||||||
choices=YEAR_IN_SCHOOL_CHOICES,
|
choices=YEAR_IN_SCHOOL_CHOICES,
|
||||||
default=FRESHMAN)
|
default=FRESHMAN,
|
||||||
|
)
|
||||||
|
|
||||||
def is_upperclass(self):
|
def is_upperclass(self):
|
||||||
return self.year_in_school in (self.JUNIOR, self.SENIOR)
|
return self.year_in_school in (self.JUNIOR, self.SENIOR)
|
||||||
|
|
|
@ -967,9 +967,10 @@ authentication app::
|
||||||
Creates and saves a superuser with the given email, date of
|
Creates and saves a superuser with the given email, date of
|
||||||
birth and password.
|
birth and password.
|
||||||
"""
|
"""
|
||||||
user = self.create_user(email,
|
user = self.create_user(
|
||||||
|
email,
|
||||||
password=password,
|
password=password,
|
||||||
date_of_birth=date_of_birth
|
date_of_birth=date_of_birth,
|
||||||
)
|
)
|
||||||
user.is_admin = True
|
user.is_admin = True
|
||||||
user.save(using=self._db)
|
user.save(using=self._db)
|
||||||
|
|
|
@ -249,9 +249,11 @@ in ``myapp``::
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
content_type = ContentType.objects.get_for_model(BlogPost)
|
content_type = ContentType.objects.get_for_model(BlogPost)
|
||||||
permission = Permission.objects.create(codename='can_publish',
|
permission = Permission.objects.create(
|
||||||
|
codename='can_publish',
|
||||||
name='Can Publish Posts',
|
name='Can Publish Posts',
|
||||||
content_type=content_type)
|
content_type=content_type,
|
||||||
|
)
|
||||||
|
|
||||||
The permission can then be assigned to a
|
The permission can then be assigned to a
|
||||||
:class:`~django.contrib.auth.models.User` via its ``user_permissions``
|
:class:`~django.contrib.auth.models.User` via its ``user_permissions``
|
||||||
|
|
|
@ -849,14 +849,16 @@ precede the definition of any keyword arguments. For example::
|
||||||
|
|
||||||
Poll.objects.get(
|
Poll.objects.get(
|
||||||
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6)),
|
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6)),
|
||||||
question__startswith='Who')
|
question__startswith='Who',
|
||||||
|
)
|
||||||
|
|
||||||
... would be a valid query, equivalent to the previous example; but::
|
... would be a valid query, equivalent to the previous example; but::
|
||||||
|
|
||||||
# INVALID QUERY
|
# INVALID QUERY
|
||||||
Poll.objects.get(
|
Poll.objects.get(
|
||||||
question__startswith='Who',
|
question__startswith='Who',
|
||||||
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6)))
|
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
|
||||||
|
)
|
||||||
|
|
||||||
... would not be valid.
|
... would not be valid.
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,13 @@ In two lines::
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
|
||||||
send_mail('Subject here', 'Here is the message.', 'from@example.com',
|
send_mail(
|
||||||
['to@example.com'], fail_silently=False)
|
'Subject here',
|
||||||
|
'Here is the message.',
|
||||||
|
'from@example.com',
|
||||||
|
['to@example.com'],
|
||||||
|
fail_silently=False,
|
||||||
|
)
|
||||||
|
|
||||||
Mail is sent using the SMTP host and port specified in the
|
Mail is sent using the SMTP host and port specified in the
|
||||||
:setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The
|
:setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The
|
||||||
|
@ -149,8 +154,12 @@ Examples
|
||||||
This sends a single email to john@example.com and jane@example.com, with them
|
This sends a single email to john@example.com and jane@example.com, with them
|
||||||
both appearing in the "To:"::
|
both appearing in the "To:"::
|
||||||
|
|
||||||
send_mail('Subject', 'Message.', 'from@example.com',
|
send_mail(
|
||||||
['john@example.com', 'jane@example.com'])
|
'Subject',
|
||||||
|
'Message.',
|
||||||
|
'from@example.com',
|
||||||
|
['john@example.com', 'jane@example.com'],
|
||||||
|
)
|
||||||
|
|
||||||
This sends a message to john@example.com and jane@example.com, with them both
|
This sends a message to john@example.com and jane@example.com, with them both
|
||||||
receiving a separate email::
|
receiving a separate email::
|
||||||
|
@ -281,9 +290,15 @@ For example::
|
||||||
|
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
|
||||||
email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email = EmailMessage(
|
||||||
['to1@example.com', 'to2@example.com'], ['bcc@example.com'],
|
'Hello',
|
||||||
reply_to=['another@example.com'], headers={'Message-ID': 'foo'})
|
'Body goes here',
|
||||||
|
'from@example.com',
|
||||||
|
['to1@example.com', 'to2@example.com'],
|
||||||
|
['bcc@example.com'],
|
||||||
|
reply_to=['another@example.com'],
|
||||||
|
headers={'Message-ID': 'foo'},
|
||||||
|
)
|
||||||
|
|
||||||
The class has the following methods:
|
The class has the following methods:
|
||||||
|
|
||||||
|
@ -405,10 +420,14 @@ It can also be used as a context manager, which will automatically call
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
|
||||||
with mail.get_connection() as connection:
|
with mail.get_connection() as connection:
|
||||||
mail.EmailMessage(subject1, body1, from1, [to1],
|
mail.EmailMessage(
|
||||||
connection=connection).send()
|
subject1, body1, from1, [to1],
|
||||||
mail.EmailMessage(subject2, body2, from2, [to2],
|
connection=connection,
|
||||||
connection=connection).send()
|
).send()
|
||||||
|
mail.EmailMessage(
|
||||||
|
subject2, body2, from2, [to2],
|
||||||
|
connection=connection,
|
||||||
|
).send()
|
||||||
|
|
||||||
Obtaining an instance of an email backend
|
Obtaining an instance of an email backend
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
@ -592,15 +611,28 @@ manually open the connection, you can control when it is closed. For example::
|
||||||
connection.open()
|
connection.open()
|
||||||
|
|
||||||
# Construct an email message that uses the connection
|
# Construct an email message that uses the connection
|
||||||
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email1 = mail.EmailMessage(
|
||||||
['to1@example.com'], connection=connection)
|
'Hello',
|
||||||
|
'Body goes here',
|
||||||
|
'from@example.com',
|
||||||
|
['to1@example.com'],
|
||||||
|
connection=connection,
|
||||||
|
)
|
||||||
email1.send() # Send the email
|
email1.send() # Send the email
|
||||||
|
|
||||||
# Construct two more messages
|
# Construct two more messages
|
||||||
email2 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
email2 = mail.EmailMessage(
|
||||||
['to2@example.com'])
|
'Hello',
|
||||||
email3 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
|
'Body goes here',
|
||||||
['to3@example.com'])
|
'from@example.com',
|
||||||
|
['to2@example.com'],
|
||||||
|
)
|
||||||
|
email3 = mail.EmailMessage(
|
||||||
|
'Hello',
|
||||||
|
'Body goes here',
|
||||||
|
'from@example.com',
|
||||||
|
['to3@example.com'],
|
||||||
|
)
|
||||||
|
|
||||||
# Send the two emails in a single call -
|
# Send the two emails in a single call -
|
||||||
connection.send_messages([email2, email3])
|
connection.send_messages([email2, email3])
|
||||||
|
|
|
@ -195,8 +195,10 @@ we'll discuss in a moment.)::
|
||||||
|
|
||||||
class AuthorForm(forms.Form):
|
class AuthorForm(forms.Form):
|
||||||
name = forms.CharField(max_length=100)
|
name = forms.CharField(max_length=100)
|
||||||
title = forms.CharField(max_length=3,
|
title = forms.CharField(
|
||||||
widget=forms.Select(choices=TITLE_CHOICES))
|
max_length=3,
|
||||||
|
widget=forms.Select(choices=TITLE_CHOICES),
|
||||||
|
)
|
||||||
birth_date = forms.DateField(required=False)
|
birth_date = forms.DateField(required=False)
|
||||||
|
|
||||||
class BookForm(forms.Form):
|
class BookForm(forms.Form):
|
||||||
|
@ -585,8 +587,12 @@ the field declaratively and setting its ``validators`` parameter::
|
||||||
For example, if the ``Article`` model looks like this::
|
For example, if the ``Article`` model looks like this::
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
headline = models.CharField(max_length=200, null=True, blank=True,
|
headline = models.CharField(
|
||||||
help_text="Use puns liberally")
|
max_length=200,
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
help_text='Use puns liberally',
|
||||||
|
)
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
|
|
||||||
and you want to do some custom validation for ``headline``, while keeping
|
and you want to do some custom validation for ``headline``, while keeping
|
||||||
|
@ -594,8 +600,11 @@ the field declaratively and setting its ``validators`` parameter::
|
||||||
``ArticleForm`` like this::
|
``ArticleForm`` like this::
|
||||||
|
|
||||||
class ArticleForm(ModelForm):
|
class ArticleForm(ModelForm):
|
||||||
headline = MyFormField(max_length=200, required=False,
|
headline = MyFormField(
|
||||||
help_text="Use puns liberally")
|
max_length=200,
|
||||||
|
required=False,
|
||||||
|
help_text='Use puns liberally',
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Article
|
model = Article
|
||||||
|
@ -1018,8 +1027,10 @@ formset::
|
||||||
def manage_authors(request):
|
def manage_authors(request):
|
||||||
AuthorFormSet = modelformset_factory(Author, fields=('name', 'title'))
|
AuthorFormSet = modelformset_factory(Author, fields=('name', 'title'))
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
formset = AuthorFormSet(request.POST, request.FILES,
|
formset = AuthorFormSet(
|
||||||
queryset=Author.objects.filter(name__startswith='O'))
|
request.POST, request.FILES,
|
||||||
|
queryset=Author.objects.filter(name__startswith='O'),
|
||||||
|
)
|
||||||
if formset.is_valid():
|
if formset.is_valid():
|
||||||
formset.save()
|
formset.save()
|
||||||
# Do something.
|
# Do something.
|
||||||
|
|
|
@ -66,8 +66,9 @@ MIME type :mimetype:`application/xhtml+xml`::
|
||||||
|
|
||||||
def my_view(request):
|
def my_view(request):
|
||||||
# View code here...
|
# View code here...
|
||||||
return render(request, 'myapp/index.html', {"foo": "bar"},
|
return render(request, 'myapp/index.html', {
|
||||||
content_type="application/xhtml+xml")
|
'foo': 'bar',
|
||||||
|
}, content_type='application/xhtml+xml')
|
||||||
|
|
||||||
This example is equivalent to::
|
This example is equivalent to::
|
||||||
|
|
||||||
|
@ -78,8 +79,7 @@ This example is equivalent to::
|
||||||
# View code here...
|
# View code here...
|
||||||
t = loader.get_template('myapp/index.html')
|
t = loader.get_template('myapp/index.html')
|
||||||
c = {'foo': 'bar'}
|
c = {'foo': 'bar'}
|
||||||
return HttpResponse(t.render(c, request),
|
return HttpResponse(t.render(c, request), content_type='application/xhtml+xml')
|
||||||
content_type="application/xhtml+xml")
|
|
||||||
|
|
||||||
``render_to_response()``
|
``render_to_response()``
|
||||||
========================
|
========================
|
||||||
|
|
|
@ -435,7 +435,8 @@ traceback by adding the following to your settings file::
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings(
|
warnings.filterwarnings(
|
||||||
'error', r"DateTimeField .* received a naive datetime",
|
'error', r"DateTimeField .* received a naive datetime",
|
||||||
RuntimeWarning, r'django\.db\.models\.fields')
|
RuntimeWarning, r'django\.db\.models\.fields',
|
||||||
|
)
|
||||||
|
|
||||||
Fixtures
|
Fixtures
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -468,8 +468,10 @@ If the string contains exactly one unnamed placeholder, you can interpolate
|
||||||
directly with the ``number`` argument::
|
directly with the ``number`` argument::
|
||||||
|
|
||||||
class MyForm(forms.Form):
|
class MyForm(forms.Form):
|
||||||
error_message = ungettext_lazy("You provided %d argument",
|
error_message = ungettext_lazy(
|
||||||
"You provided %d arguments")
|
"You provided %d argument",
|
||||||
|
"You provided %d arguments",
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# ...
|
# ...
|
||||||
|
@ -1817,8 +1819,11 @@ If you need more flexibility, you could also add a new argument to your custom
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
super(Command, self).add_arguments(parser)
|
super(Command, self).add_arguments(parser)
|
||||||
parser.add_argument('--extra-keyword', dest='xgettext_keywords',
|
parser.add_argument(
|
||||||
action='append')
|
'--extra-keyword',
|
||||||
|
dest='xgettext_keywords',
|
||||||
|
action='append',
|
||||||
|
)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
xgettext_keywords = options.pop('xgettext_keywords')
|
xgettext_keywords = options.pop('xgettext_keywords')
|
||||||
|
|
Loading…
Reference in New Issue