From a4a183f7022d4a69fc896467a8ff367f539acdc9 Mon Sep 17 00:00:00 2001 From: Fabian Faessler Date: Sat, 28 Sep 2013 13:04:21 +0200 Subject: [PATCH] added URL and simple view to get the user IP in a json format {'ip': '127.0.0.1'} --- nsupdate/main/urls.py | 3 ++- nsupdate/main/views.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index 944d2f8..d50c085 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import patterns, include, url -from main.views import HomeView +from main.views import HomeView, MyIpView urlpatterns = patterns('', url(r'^$', HomeView.as_view(), name="home"), + url(r'^myip/', MyIpView) ) diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index d8ec9df..506a129 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- - from django.views.generic import TemplateView +from django.http import HttpResponse +import json class HomeView(TemplateView): template_name = "base.html" @@ -9,3 +10,6 @@ class HomeView(TemplateView): context = super(HomeView, self).get_context_data(*args, **kwargs) context['nav_home'] = True return context + +def MyIpView(request): + return HttpResponse(json.dumps({'ip':request.META['REMOTE_ADDR']}), content_type="application/json") \ No newline at end of file