On 28/05/2024 9:09 pm, Antonis Christofides wrote:
Hello,

I use the sites framework for a Django project that serves many different domains. But each of those domains has some templates overridden.

Might depend on what you are overriding - entire templates or just includes or just vars.

I would probably start by refactoring the templates so they were identical for all sites and reduce/extract the differences to includes which can be selected via contextvars after calling get_current_site() from the view.

Have you looked at template tags?

I use them for displaying additional information on the staging and dev sites versus production. Not what you are doing so I haven't thought too hard about that. Only worth a thought if you haven't considered it.


If I used a different instance of Django (i.e. a different gunicorn service) for each domain, I'd have different settings for each site. But I'm using a single instance to serve all sites and, wherever I need to, I use things that extract the domain from the request, like `get_current_site()`. But this doesn't seem to work with templates. A custom template loader won't work without a fight because its methods don't accept the request object as an argument.

All solutions I've thought about are ugly hacks.

Practicality beats purity

The least ugly seems to be to create middleware that stores the request object in a contextvar <https://docs.python.org/3/library/contextvars.html>. But it strikes me that I can't find a simpler solution for this. Is what I want that uncommon, or am I missing something?

There's an old closed "wontfix" ticket <https://code.djangoproject.com/ticket/13500> about this but without adequate explanation.
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/175b4601-2038-479b-9581-48d9c196df7cn%40googlegroups.com <https://groups.google.com/d/msgid/django-users/175b4601-2038-479b-9581-48d9c196df7cn%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
We recommend signal.org

Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/befa4ac2-40b8-44da-87c2-cbbe3ed307c6%40dewhirst.com.au.

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to