New Django user: How do I return the server's IP address?

2,486 views
Skip to first unread message

dav...@gmail.com

unread,
Nov 21, 2008, 5:14:56 PM11/21/08
to Django users
Where can I get the Host server's IP address?

request.META['SERVER_NAME'] simply returns localhost instead of
whatever my ip address is

Thanks.

Karen Tracey

unread,
Nov 21, 2008, 6:14:52 PM11/21/08
to django...@googlegroups.com

Your machine likely has more than one IP address: one for each network interface, including the local loopback interface, so usually at least two when actually connected to a network.  Which one do you want?

More importantly -- what is the real problem you are trying to solve?  I have a feeling you are not asking the right question to solve it.

Karen

Steve Holden

unread,
Nov 21, 2008, 6:15:35 PM11/21/08
to django...@googlegroups.com
Try

import socket
socket.gethostbyname(request.META['SERVER_NAME'])

regards
Steve

Reply all
Reply to author
Forward
0 new messages