Django:在settings.py中获取远程IP地址

Sil*_*ght 1 python django

我想启用debug(DEBUG = True)仅适用于我的Django项目在localhost上运行.如何在settings.py中获取用户IP地址?我希望这样的工作:

#Debugging only on localhost
if user_ip = '127.0.0.1':
    DEBUG = True
else:
    DEBUG = False 
Run Code Online (Sandbox Code Playgroud)

如何将用户IP地址放在user_ip变量内部settings.py文件中?