Skip to content

Fix minor errors in topic guide examples #19697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rohit10jr
Copy link

This PR corrects few minor issues in the Django topic guides:

  • Fixed incorrect use of request instead of self.request in the
    JsonableResponseMixin example.
  • Corrected import errors in code snippets.
  • Fixed small typos and inconsistencies across topic guides.

These changes improve the accuracy of the documentation examples, ensuring
They can be copied and run without errors.

Previously, the documentation showed:
>>> type(p.page_range)
<class 'range_iterator'>

However, in actual usage, this returns:
<class 'range'>

This commit corrects the example to reflect the accurate return type observed during runtime.
Updated example to use `/` operator for building paths 
instead of string concatenation. Also noted that comparison between 
car.photo.path (string) and new_path (Path) requires str() conversion.

- Replaced '+' with '/' for Path joining
- Used str(new_path) to ensure equality check works
The django CBV documentation example was missing the @never_cache decorator.
Replaced incorrect `request` with `self.request` in form_invalid and form_valid methods to properly access the request.
@github-actions github-actions bot added the no ticket Based on PR title, no linked Trac ticket label Aug 2, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestions!
I have some minor comments

@@ -70,13 +70,13 @@ location (:setting:`MEDIA_ROOT` if you are using the default
>>> from django.conf import settings
>>> initial_path = car.photo.path
>>> car.photo.name = "cars/chevy_ii.jpg"
>>> new_path = settings.MEDIA_ROOT + car.photo.name
>>> new_path = settings.MEDIA_ROOT / car.photo.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> new_path = settings.MEDIA_ROOT / car.photo.name
>>> new_path = os.path.join(settings.MEDIA_ROOT, car.photo.name)

The suggestion errors, I believe the above might be what's needed

>>> # Move the file on the filesystem
>>> os.rename(initial_path, new_path)
>>> car.save()
>>> car.photo.path
'/media/cars/chevy_ii.jpg'
>>> car.photo.path == new_path
>>> car.photo.path == str(new_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> car.photo.path == str(new_path)
>>> car.photo.path == new_path

I don't think this is required

@@ -275,6 +275,7 @@ function decorator into a method decorator so that it can be used on an
instance method. For example::

from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import never_cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from django.views.decorators.cache import never_cache

I would drop this, it's not needed for the initial example and for the example
We could add it to the example lower down but I think the concept it is showing is clear enough without the import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no ticket Based on PR title, no linked Trac ticket
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants