Mercurial > sat_legacy_website
diff sat_website/views.py @ 138:2ec5653b190a
add url "whereami" to get the client IP address
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 26 Apr 2016 19:32:44 +0200 |
parents | c56b6ad62153 |
children | d0cd185f9b61 |
line wrap: on
line diff
--- a/sat_website/views.py Tue Mar 08 08:59:13 2016 +0100 +++ b/sat_website/views.py Tue Apr 26 19:32:44 2016 +0200 @@ -20,7 +20,7 @@ You should have received a copy of the GNU Affero General Public License along with Foobar. If not, see <http://www.gnu.org/licenses/>. """ -from django.http import Http404 +from django.http import Http404, HttpResponse from django.shortcuts import render_to_response from django.core.context_processors import csrf from django.utils.translation import ugettext_lazy as _ @@ -68,9 +68,11 @@ 'libervia': _(u'Libervia frontend (web server and client)'), } + def overview(request): return render_to_response('sat_website/overview.html') + def generic_cat(request, category): if category in CATEGORIES_ALIASES: category = CATEGORIES_ALIASES[category] @@ -120,3 +122,13 @@ return render_to_response('sat_website/%s.html' % (category,), context) else: raise Http404 + + +def whereami(request): + """Return the client IP address""" + x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') + if x_forwarded_for: + ip = x_forwarded_for.split(',')[0] + else: + ip = request.META.get('REMOTE_ADDR') + return HttpResponse(ip)