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