Closed venteto closed 2 years ago
This is more of a Django question than a django-distill
question. If you configure Django itself to support multiple URLs for a single Django installation you can then get django-distill
to render just one of the sites. From some quick searching, here's some suggested links:
https://www.valentinog.com/blog/django-vhosts/
https://pypi.org/project/django-multi-domains/
Once you have a multi-domain Django install working you can do something like set an override host in settings.py
from an ENV var:
OVERRIDE_HOST = os.getenv('OVERRIDE_HOST')
Then in your assumed new MiddleWare you would do some sort of check (see above links for full examples):
host = settings.OVERRIDE_HOST if settings.OVERRIDE_HOST else request.get_host()
And finally, you could set the host when you call django-distill
:
OVERRIDE_HOST=www.example.com python3 manage.py distill-local /some/directory
Unless you have any follow-up questions or issues I'll close this in a few days.
That's cool, and thanks anyhow. I was actually talking about this though:
Sure, exactly the same question and I was covering the Sites framework as well with the above. For example:
from django.contrib.sites.models import Site
from django.contrib.sites.shortcuts import get_current_site
def get_current_site_with_override(request):
try:
return Site.objects.get(domain=settings.OVERRIDE_HOST)
except Site.DoesNotExist:
return get_current_site(request)
Which would change the returned Site object depending on your usage of OVERRIDE_HOST env var on the command line, assuming you also edited your settings.py
.
Basically you just need to get the site from the command line and use it in your project, but default to the usual behaviour if the override isn't set.
I'll close this issue for now but feel free to comment if you still need further assistance and I'll re-open it.
E.g., can you have multiple distill directory settings or something? Then have separate Netlify sites consume different output directories in one GitHub repo?