python - Excluding a Django app from being localized using a middleware -
i need localize django project, keep 1 of applications (the blog) english only.
i wrote middleware in order achieve this:
from django.conf import settings django.core.urlresolvers import resolve class delocalizemiddleware: def process_request(self, request): current_app_name = __name__.split('.')[-2] match = resolve(request.path) if match.app_name == current_app_name: request.language_code = settings.language_code
problem is, assumes middleware lies directly in application module (e.g. blog/middleware.py) retrieving app name. other projects might have middleware in blog/middleware/delocalize.py or else altogether.
what's best way retrieve name of running app?
you can use django's resolve
function current app name.
https://docs.djangoproject.com/en/dev/topics/http/urls/#resolve
Comments
Post a Comment