Я хотел бы предложить улучшение ответа яньченко.
Вместо того, чтобы принимать первый ip в списке X_FORWARDED_FOR, я беру первый, который не является известным внутренним ip, поскольку некоторые роутеры надевают ' t уважение к протоколу, и вы можете увидеть внутреннее ips как первое значение списка.
PRIVATE_IPS_PREFIX = ('10.', '172.', '192.', )
def get_client_ip(request):
"""get the client ip from the request
"""
remote_address = request.META.get('REMOTE_ADDR')
# set the default value of the ip to be the REMOTE_ADDR if available
# else None
ip = remote_address
# try to get the first non-proxy ip (not a private ip) from the
# HTTP_X_FORWARDED_FOR
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
proxies = x_forwarded_for.split(',')
# remove the private ips from the beginning
while (len(proxies) > 0 and
proxies[0].startswith(PRIVATE_IPS_PREFIX)):
proxies.pop(0)
# take the first ip which is not a private one (of a proxy)
if len(proxies) > 0:
ip = proxies[0]
return ip
Надеюсь, это поможет собратьям Google, которые имеют ту же проблему.
С помощью props.navigation.state.routes [0] .routes.slice (-1) [0] .routeName я могу получить активный маршрутизатор, чтобы иметь возможность стилизовать. Если у вас есть лучший способ, я был бы рад прочитать.
Не совсем то, что я ожидал, но сейчас это работает хорошо:
export default (CustomDrawerContentComponent = props => {
const activeRouterName = props.navigation.state.routes[0].routes.slice(-1)[0].routeName
return (
<ScrollView>
<TouchableOpacity onPress={() => props.navigation.closeDrawer()} style={styles.close}>
<EvilIcons style={{ color: color.dark.contrast }} size={40} name="close" />
</TouchableOpacity>
<View style={styles.thumbImageContainer}>
<ThumbImage source={require('../assets/images/user.jpg')} />
<View style={styles.statusContainer}>
<TextApp dark>Luis Coimbra</TextApp>
<TextApp secondary>Apaixonado por Jesus</TextApp>
</View>
</View>
<SafeAreaView
style={{ flex: 1, borderTopWidth: 2, borderTopColor: color.dark.contrast }}
forceInset={{ top: 'always', horizontal: 'never' }}
>
{['Início', 'Perfil', 'Notificações', 'Criar Evento'].map(routerName => (
<View key={routerName} style={routerName == activeRouterName && styles.activeView}>
<TextApp
onPress={() => props.navigation.navigate(routerName)}
style={{
color:
routerName == activeRouterName
? color.secondary()
: color.dark.contrast,
margin: 16,
fontWeight: 'bold'
}}
>
{routerName}
</TextApp>
</View>
))}
</SafeAreaView>
</ScrollView>
)
})
Результат: