পুনঃনির্দেশ ছাড়াই স্ল্যাশ যুক্ত করুন , সেটিংসে কমনমিলডওয়ারের পরিবর্তে এটি ব্যবহার করুন, জাজানো ২.১:
MIDDLEWARE = [
...
'htx.middleware.CommonMiddlewareAppendSlashWithoutRedirect',
...
]
আপনার মূল অ্যাপ্লিকেশন ডিরেক্টরিতে মিডওয়ারওয়্যার যুক্ত করুন :
from django.http import HttpResponsePermanentRedirect, HttpRequest
from django.core.handlers.base import BaseHandler
from django.middleware.common import CommonMiddleware
from django.conf import settings
class HttpSmartRedirectResponse(HttpResponsePermanentRedirect):
pass
class CommonMiddlewareAppendSlashWithoutRedirect(CommonMiddleware):
""" This class converts HttpSmartRedirectResponse to the common response
of Django view, without redirect.
"""
response_redirect_class = HttpSmartRedirectResponse
def __init__(self, *args, **kwargs):
self.handler = BaseHandler()
old = settings.MIDDLEWARE
name = self.__module__ + '.' + self.__class__.__name__
settings.MIDDLEWARE = [i for i in settings.MIDDLEWARE if i != name]
self.handler.load_middleware()
settings.MIDDLEWARE = old
super(CommonMiddlewareAppendSlashWithoutRedirect, self).__init__(*args, **kwargs)
def process_response(self, request, response):
response = super(CommonMiddlewareAppendSlashWithoutRedirect, self).process_response(request, response)
if isinstance(response, HttpSmartRedirectResponse):
if not request.path.endswith('/'):
request.path = request.path + '/'
request.path_info = request.path
response = self.handler.get_response(request)
return response