1
0
mirror of https://github.com/django/django.git synced 2025-08-25 19:29:14 +00:00

[5.2.x] Corrected code examples in topics docs.

Backport of fa804d0d14ef4547b4fe2a88ab5d89d4eed5bacd from main.
This commit is contained in:
Rohit 2025-08-11 09:09:16 +02:00 committed by Sarah Boyce
parent ad836aa0c5
commit 1d9f6c3270
3 changed files with 4 additions and 4 deletions

View File

@ -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":

View File

@ -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()

View File

@ -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)