-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Fixed #13559 -- Added context processor for the site framework. #20033
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
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 ⛵️!
fe2eec3 to
252195d
Compare
|
|
||
| def site(request): | ||
| """Returns a context variable with the current site.""" | ||
| return {"site": get_current_site(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.
This adds a (potential) database query on every template render, which is unfortunate for performance and can cause problems for custom error views, as I covered in this post.
Can we instead make site a lazy object, like request.user is? (An alternative is to use functools.cache, as I covered in that post.)
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.
Hi and thanks for the review!
I'm not sure how the implementation in https://github.com/django/django/blob/main/django/contrib/auth/context_processors.py is different from what I had done, so I've used your functools.cache alternative.
As a more general rule, shouldn't your generic test_context_managers_no_queries be included directly in Django?
docs/ref/contrib/sites.txt
Outdated
| lawrence.com alerts." On LJWorld.com, the email has the subject "Thanks for | ||
| subscribing to LJWorld.com alerts." Same goes for the email's message body. | ||
|
|
||
| Using ``site`` in templates |
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.
This section appears to have been inserted randomly in the middle of a discussion about using sites in emails. Did you make a mistake?
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.
For this comment and the next one: I'm not sure on where this is supposed to be and to go, so I simply reimplemented what was in #1938. I'm open to suggestions :)
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.
Sorry, I don't have time to read this whole documentation section and decide what to do, but I'm happy to review any change you can come up with.
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.
I moved it further down in the doc.
docs/ref/contrib/sites.txt
Outdated
| lawrence.com alerts." On LJWorld.com, the email has the subject "Thanks for | ||
| subscribing to LJWorld.com alerts." Same goes for the email's message body. | ||
|
|
||
| Using ``site`` in templates |
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.
Sorry, I don't have time to read this whole documentation section and decide what to do, but I'm happy to review any change you can come up with.
… the place that makes more sense.
Trac ticket number
ticket-13559
Branch description
This is a rewriting of #1938, taking in account the comments at the time. I also changed the tests that were originally made for Django 1.8.
This task was listed in the "doable" tickets during the Django sprint at PyconFr 2025.
Checklist
mainbranch.