You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: | GET
http://localhost:8000/accounts/login/?next=/silk/
TemplateDoesNotExist
registration/login.html
Solution
Being able to specify either a path, or arguments to django's reverse(), to resolve the correct redirection in the event of an unauthorised user would solve this.
Workaround
I used middleware to redirect users to log into the admin before accessing silk endpoints:
fromdjango.shortcutsimportredirectfromdjango.urlsimportreversefromdjango.utils.httpimporturlencodeclassSilkyStaffMiddleware:
""" Middleware to ensure only authenticated staff users can access Silk URLs. """def__init__(self, get_response):
self.get_response=get_responsedef__call__(self, request):
ifrequest.path.startswith('/silk/'):
ifnot (request.user.is_authenticatedandrequest.user.is_staff):
login_url=reverse('admin:login')
query_string=urlencode({'next': request.path})
returnredirect(f"{login_url}?{query_string}")
returnself.get_response(request)
The text was updated successfully, but these errors were encountered:
Problem
I get a template error when using Silk's authentication/authorisation.
With settings:
The error is:
Solution
Being able to specify either a path, or arguments to django's
reverse()
, to resolve the correct redirection in the event of an unauthorised user would solve this.Workaround
I used middleware to redirect users to log into the admin before accessing silk endpoints:
The text was updated successfully, but these errors were encountered: