0
Heroku에서 배포하려고하면 웹 사이트에서이 코드로 리디렉션 루프가 발생합니다. 다음은 미들웨어 코드입니다.django 미들웨어에서 HTTP HttpResponsePermanentRedirect를 사용할 때 사이트가 리디렉션 루프로 들어갑니다.
# -*- coding: utf-8 -*-
from django.utils.functional import SimpleLazyObject
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
def get_country_request(ip):
import pygeoip
file_path = settings.PROJECT_ROOT + '/data/GeoIP.dat.dat'
gi = pygeoip.GeoIP(file_path)
country = gi.country_name_by_addr(ip)
if country:
return country
class LocationMiddleWare(object):
def process_request(self, request):
if 'HTTP_X_FORWARDED_FOR' in request.META:
request.META['REMOTE_ADDR'] = request.META['HTTP_X_FORWARDED_FOR']
ip = request.META['REMOTE_ADDR']
print request.path
country = get_country_request(ip)
if country == "India":
return HttpResponsePermanentRedirect('/en/')
if country == "Netherlands":
return HttpResponsePermanentRedirect('/nl/')
return None
어디서 잘못했는지 제안하고 더 나은 방법이 있는지 제안하십시오.
미리 감사드립니다.
감사합니다. 당신은 끝내줍니다 :) –
도움이되기를 기쁘게 생각합니다 :) – tayfun