-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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 ⛵️!
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
This PR corrects few minor issues in the Django topic guides:
request
instead ofself.request
in theJsonableResponseMixin example.
These changes improve the accuracy of the documentation examples, ensuring
They can be copied and run without errors.