Advertisement
oquidave

django urls

Nov 20th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. """
  2. how do i pass get parameters, the old school way like http://localhost:8000/check_serverip/?ip=127.0.0.1
  3. and using django pretty url(don't know how i would pass that) to my views?
  4. """
  5.  
  6. #url.py
  7.  
  8. from django.conf.urls import patterns, include, url
  9.  
  10. from django.contrib import admin
  11. from monitor import views
  12. admin.autodiscover()
  13.  
  14. urlpatterns = patterns('',
  15.     # Examples:
  16.     # url(r'^$', 'sysradar.views.home', name='home'),
  17.     # url(r'^blog/', include('blog.urls')),
  18.     url(r'^check_serverip/$', views.check_serverip),
  19.     url(r'^admin/', include(admin.site.urls)),
  20. )
  21.  
  22.  
  23. #views.py
  24. from django.shortcuts import render
  25. from django.http import HttpResponse
  26. from radar.server_radar.checkserver import MyBox
  27.  
  28. # Create your views here.
  29.  
  30.  
  31. def check_serverip(request):
  32.     ip = request.GET.get('ip', '')
  33.     box = MyBox()
  34.     box_status = box.box_alive(ip)
  35.     return HttpResponse("The Box with IP: %s is %s" % (ip, box_status))
  36.    
  37.    
  38. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement