added URL and simple view to get the user IP in a json format {'ip': '127.0.0.1'}
This commit is contained in:
parent
0d628f35e0
commit
a4a183f702
@ -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)
|
||||
)
|
||||
|
@ -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")
|
Loading…
x
Reference in New Issue
Block a user