-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2033a33
commit 2e1900f
Showing
4 changed files
with
22 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.conf import settings | ||
from django_hosts.resolvers import reverse_host | ||
from django.http import HttpResponseRedirect, HttpResponse | ||
from django.http import HttpRequest | ||
from django.utils.deprecation import MiddlewareMixin | ||
|
||
|
||
class RedirectAdminMiddleware(MiddlewareMixin): | ||
def process_request(self, request: HttpRequest) -> HttpResponse: | ||
if (request.path.startswith('/admin/') and | ||
request.method == 'GET' and | ||
request.headers.get('Accept', '').startswith('text/html')): | ||
protocol = 'https' if request.is_secure() else 'http' | ||
host = reverse_host('admin') | ||
if getattr(settings, 'HOST_PORT', None): | ||
host = f"{host}:{settings.HOST_PORT}" | ||
path = request.path[7:] # Remove '/admin/' | ||
return HttpResponseRedirect(f'{protocol}://{host}/{path}') | ||
return None |
This file was deleted.
Oops, something went wrong.
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