mirror of
https://github.com/django/django.git
synced 2025-08-21 01:09:13 +00:00
Corrected code examples in topics docs.
This commit is contained in:
parent
7a80e29fea
commit
fa804d0d14
@ -303,7 +303,7 @@ preference, use :func:`django.http.HttpRequest.get_preferred_type`::
|
|||||||
|
|
||||||
def form_invalid(self, form):
|
def form_invalid(self, form):
|
||||||
response = super().form_invalid(form)
|
response = super().form_invalid(form)
|
||||||
accepted_type = request.get_preferred_type(self.accepted_media_types)
|
accepted_type = self.request.get_preferred_type(self.accepted_media_types)
|
||||||
if accepted_type == "text/html":
|
if accepted_type == "text/html":
|
||||||
return response
|
return response
|
||||||
elif accepted_type == "application/json":
|
elif accepted_type == "application/json":
|
||||||
@ -314,7 +314,7 @@ preference, use :func:`django.http.HttpRequest.get_preferred_type`::
|
|||||||
# it might do some processing (in the case of CreateView, it will
|
# it might do some processing (in the case of CreateView, it will
|
||||||
# call form.save() for example).
|
# call form.save() for example).
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
accepted_type = request.get_preferred_type(self.accepted_media_types)
|
accepted_type = self.request.get_preferred_type(self.accepted_media_types)
|
||||||
if accepted_type == "text/html":
|
if accepted_type == "text/html":
|
||||||
return response
|
return response
|
||||||
elif accepted_type == "application/json":
|
elif accepted_type == "application/json":
|
||||||
|
@ -70,7 +70,7 @@ location (:setting:`MEDIA_ROOT` if you are using the default
|
|||||||
>>> from django.conf import settings
|
>>> from django.conf import settings
|
||||||
>>> initial_path = car.photo.path
|
>>> initial_path = car.photo.path
|
||||||
>>> car.photo.name = "cars/chevy_ii.jpg"
|
>>> car.photo.name = "cars/chevy_ii.jpg"
|
||||||
>>> new_path = settings.MEDIA_ROOT + car.photo.name
|
>>> new_path = os.path.join(settings.MEDIA_ROOT, car.photo.name)
|
||||||
>>> # Move the file on the filesystem
|
>>> # Move the file on the filesystem
|
||||||
>>> os.rename(initial_path, new_path)
|
>>> os.rename(initial_path, new_path)
|
||||||
>>> car.save()
|
>>> car.save()
|
||||||
|
@ -31,7 +31,7 @@ accessing the items for each page:
|
|||||||
>>> p.num_pages
|
>>> p.num_pages
|
||||||
2
|
2
|
||||||
>>> type(p.page_range)
|
>>> type(p.page_range)
|
||||||
<class 'range_iterator'>
|
<class 'range'>
|
||||||
>>> p.page_range
|
>>> p.page_range
|
||||||
range(1, 3)
|
range(1, 3)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user