added URL and simple view to get the user IP in a json format {'ip': '127.0.0.1'}

This commit is contained in:
Fabian Faessler 2013-09-28 13:04:21 +02:00
parent 0d628f35e0
commit a4a183f702
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,7 @@
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from main.views import HomeView from main.views import HomeView, MyIpView
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^$', HomeView.as_view(), name="home"), url(r'^$', HomeView.as_view(), name="home"),
url(r'^myip/', MyIpView)
) )

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.http import HttpResponse
import json
class HomeView(TemplateView): class HomeView(TemplateView):
template_name = "base.html" template_name = "base.html"
@ -9,3 +10,6 @@ class HomeView(TemplateView):
context = super(HomeView, self).get_context_data(*args, **kwargs) context = super(HomeView, self).get_context_data(*args, **kwargs)
context['nav_home'] = True context['nav_home'] = True
return context return context
def MyIpView(request):
return HttpResponse(json.dumps({'ip':request.META['REMOTE_ADDR']}), content_type="application/json")