This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a MULTISITE_FALLBACK view to create Alias entry
See also: ecometrica/django-multisite#33
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
from django.conf import settings | ||
from django.contrib.sites.models import Site | ||
from django.http import HttpResponseRedirect | ||
|
||
from multisite.models import Alias | ||
|
||
|
||
def multisite_fallback_view(request): | ||
""" | ||
Create a multisite.models.Alias entry for the current host. | ||
Use the default SITE_ID. | ||
Use by add this into settings: | ||
MULTISITE_FALLBACK="pylucid.multisite_views.multisite_fallback_view" | ||
""" | ||
host = request.get_host().lower() | ||
site_id = settings.SITE_ID.get_default() | ||
site = Site.objects.get(pk=site_id) | ||
|
||
# print("Create Alias for %r to SITE_ID %s" % (host, site.pk)) | ||
Alias.objects.create( | ||
domain=host, | ||
site=site, | ||
redirect_to_canonical=False, | ||
) | ||
return HttpResponseRedirect(request.get_full_path()) |