Skip to content

Conversation

@Ash-Crow
Copy link

@Ash-Crow Ash-Crow commented Oct 31, 2025

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

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

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 ⛵️!

@Ash-Crow Ash-Crow force-pushed the site-contextprocessor branch from fe2eec3 to 252195d Compare October 31, 2025 21:13

def site(request):
"""Returns a context variable with the current site."""
return {"site": get_current_site(request)}
Copy link
Member

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

Copy link
Author

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?

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
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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.

Copy link
Author

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.

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants