title: AJAX data being sent to the wrong Django view
body: <p>I'm new to django and ajax so I've been working on a project to learn it. I have two buttons, one that adds a marker and one that deletes a marker.</p>
  
  <p>Here is the views.py</p>
  
  <pre><code>@csrf_exempt
  def save(request):
      searchVar = request.POST.getlist('search[]')
      waypoint = Waypoint()
      waypoint.name = searchVar[0]
      waypoint.geometry = ('POINT(' + searchVar[2] + " " + searchVar[1] + ')')
      waypoint.save()
      return HttpResponse(json.dumps(dict(isOk=1)), content_type='application/json')
  
  @csrf_exempt
  def remove(request):
      objectID = request.POST.get('id')
      point = get_object_or_404(Point, pk = objectID)
      point.delete()
  </code></pre>
  
  <p>Here is the urls.py </p>
  
  <pre><code>from django.conf.urls import patterns, url, include
  
  urlpatterns = patterns('googlemaps.waypoints.views',
      url(r'^$', 'index', name='waypoints-index'),
      url(r'', 'save', name='waypoints-save'),
      url(r'', 'remove', name='waypoints-remove'),
  )
  </code></pre>
  
  <p>and here is the ajax from the js file</p>
  
  <pre><code>    $('#saveWaypoints').click(function () {
      var searchList = [search.name, search.geometry.location.lat(), search.geometry.location.lng()]
      $.ajax({
        url : "waypoints-save",
        type : "POST",
        data : { search : searchList }
      }, function (data) {
          if (data.isOk) {
              $('#saveWaypoints');
          } else {
              alert(data.message);
          }
      });
  });
  $('#removeWaypoints').click(function () {
    console.log(markerID);
      $.ajax({
        url : "waypoints-remove",
        type : "POST",
        data : { id : markerID }
      }, function (data) {
          if (data.isOk) {
              $('#removeWaypoints');
          } else {
              alert(data.message);
          }
      });
  });
  </code></pre>
  
  <p>The save button works fine, but when I click on the remove button I get this error in my console log</p>
  
  <pre><code>POST http://127.0.0.1:8000/waypoints-remove 500 (Internal Server Error)
  
  IndexError at /waypoints-remove
  list index out of range
  
  Request Method: POST
  Request URL: http://127.0.0.1:8000/waypoints-remove
  </code></pre>
  
  <p>and this error in my server cmd</p>
  
  <pre><code>Internal Server Error: /waypoints-remove
  Traceback (most recent call last):
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
      response = self.process_exception_by_middleware(e, request)
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)
    File "C:\Users\rnvitter\virtualenv4\googlemaps\googlemaps\waypoints\views.py", line 23, in save
      waypoint.name = searchVar[0]
  IndexError: list index out of range
  2017-01-09 22:40:11,781 - ERROR - Internal Server Error: /waypoints-remove
  Traceback (most recent call last):
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
      response = self.process_exception_by_middleware(e, request)
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Users\rnvitter\virtualenv4\myvenv\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)
    File "C:\Users\rnvitter\virtualenv4\googlemaps\googlemaps\waypoints\views.py", line 23, in save
      waypoint.name = searchVar[0]
  IndexError: list index out of range
  </code></pre>
  
  <p>Which leads me to believe that the data from the remove button ajax call is being sent to my save view, does anyone know one?</p>