Closed dannyboscan closed 7 years ago
It would be great to see this merged and released.
In the mean time, you can write your own middleware that does the same thing:
from django.utils.functional import SimpleLazyObject
from django_user_agents.utils import get_user_agent
def user_agent_middleware(get_response):
def middleware(request):
request.user_agent = SimpleLazyObject(lambda: get_user_agent(request))
return get_response(request)
return middleware
I have it installed from pip. Now how do I make the necessary changes for the middleware to work? I am not able to locate the django_user_agents/middleware.py
@digi0ps if you are using Django 1.10 just create your own Middlaware Class and references in MIDDLEWARE settings instead of django_user_agents.middleware.UserAgentMiddleware
Custom middleware:
from django.utils.deprecation import MiddlewareMixin
from django_user_agents.middleware import UserAgentMiddleware
class CustomUserAgentMiddleware(MiddlewareMixin, UserAgentMiddleware):
pass
settings.py
MIDDLEWARE = [
# other middlewares...
'path.to.your.own.file.CustomUserAgentMiddleware',
]
@dannyboscan Thanks a lot, it worked. 👍
Sorry for the delayed response. Does this PR still fixes problems on Django 1.10 and 1.11 or do we need to consider anoher approach? I can make a PyPI release sometime this week if we have a reliable fix for newer versions of Django.
Still work in Django 1.11
Fix #13