diff options
author | Kyle K <kylek389@gmail.com> | 2017-03-26 23:58:16 -0500 |
---|---|---|
committer | Kyle K <kylek389@gmail.com> | 2017-03-26 23:58:16 -0500 |
commit | b407981d418943f737a9eb76d3566dc6f913ad37 (patch) | |
tree | 3638b1c904c348f8fd3e4378f5d9e4895a8899d4 /myapp | |
parent | eb98f903635b2b10cc40271e58591e522226784d (diff) | |
download | CLscrap-b407981d418943f737a9eb76d3566dc6f913ad37.tar.gz CLscrap-b407981d418943f737a9eb76d3566dc6f913ad37.tar.bz2 CLscrap-b407981d418943f737a9eb76d3566dc6f913ad37.zip |
provide RESTful API at /api/cl pathname
Diffstat (limited to 'myapp')
-rw-r--r-- | myapp/urls.py | 3 | ||||
-rw-r--r-- | myapp/views.py | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/myapp/urls.py b/myapp/urls.py index 0ef0e5a..463b774 100644 --- a/myapp/urls.py +++ b/myapp/urls.py @@ -4,5 +4,6 @@ from . import views urlpatterns = [ url(r'^$', views.app, name='app'), # at this point /app string is consumed - url(r'^page/', views.page, name='page'), # at this point /app string is consumed as well, therefore /app/page hits this + url(r'^page', views.page, name='page'), # at this point /app string is consumed as well, therefore /app/page hits this + url(r'^cl', views.cl_scrap), ]
\ No newline at end of file diff --git a/myapp/views.py b/myapp/views.py index 10b5c99..6b014ac 100644 --- a/myapp/views.py +++ b/myapp/views.py @@ -1,7 +1,8 @@ from django.shortcuts import render # Create your views here. -from django.http import HttpResponse +from django.http import HttpResponse, JsonResponse +import cl def app(request): @@ -9,4 +10,11 @@ def app(request): def page(request): - return HttpResponse("hello, page!")
\ No newline at end of file + return HttpResponse("hello, page!") + + +def cl_scrap(request): + if request.method == 'GET': + arr = cl.query_craigslist() + ret = {'data': arr, 'items': len(arr)} + return JsonResponse(ret)
\ No newline at end of file |