简体   繁体   中英

Django: What's the correct way to get the requesting IP address?

I'm trying to develop an app using Django 1.1 on Webfaction. I'd like to get the IP address of the incoming request, but when I use request.META['REMOTE_ADDR'] it returns 127.0.0.1. There seems to be a number of different ways of getting the address, such as using HTTP_X_FORWARDED_FOR or plugging in some middleware called SetRemoteAddrFromForwardedFor. Just wondering what the best approach was?

远程代理中间件已在Django 1.1.1删除,并指出要信任REMOTE_ADDR或HTTP_X_FORWARDED仍然不安全(以防万一,这也有助于您决定要做什么)

I use the middleware because this way I don't have to change the app's code.

If I want to migrate my app to other hosting servers, I only need to modify the middleware without affecting other parts.

Security is not an issue because on WebFaction you can trust what comes in from the front end server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM