Why is the URL 404 not found with Django?
Question: I have written a Django script that runs a Python parser to web s*e. I am
sending the request to the Django script via AJAX. However, when the Ajax
runs, it comes back as 404 not found for the URL. Why is this happening?

My code is below:

Ajax (with jQuery):

    
    
    //send a `post` request up to AWS, and then 
    //insert the data into the paths
    
    $.post('/ca', function(data){
    //evaluate the JSON
    data = eval ("(" + data + ")");
    //insert the vars into the DOM
    var contentOne;
    contentOne = data.bridge_time;
    contentOne += 'min delay';
    $('#timeone').html(contentOne);
    var contentTwo;
    contentTwo = data.tunnel_time;
    contentTwo += 'min delay';
    $('#timetwo').html(contentTwo);
    //if this falls through, push an error.
    var tunnel_time = data.tunnel_time;
    var bridge_time = data.bridge_time;
    var tunnel = document.getElementById('tunnel');
    var bridge = document.getElementById('bridge');
    var tunnelText = document.getElementById('timeone');
    var bridgeText = document.getElementById('timetwo');
    //algo for the changing icons. Kudos to Vito
    if(tunnel_time<bridge_time){
      tunnel.src="tunnel3.png";
      bridge.src="bridge2r.png";
    }else if( bridge_time<tunnel_time){
      bridge.src="bridge21.png";
      tunnel.src="tunnel2r.png";
    }else{
      bridge.src="bridge2n.png";
      tunnel.src="tunnel2g.png";
    }
      $.fail(function() {
    alert("We're sorry. We are having an error. Check back later.");
    });
    });
    

My urls.py:

    
    
    from django.conf.urls.defaults import *
    from views import views
    
    urlpatterns = patterns('',
                       (r'^/us', views.american_time),
                       (r'^/ca', views.canadian_time),
    )
    

My `urls.py` and my `views.py` are in the same folder, if that makes any
difference. They are just titled **views.py** and **urls.py**. Thank you!


Answer: Try

    
    
    from django.conf.urls.defaults import *
    from views import views
    
    urlpatterns = patterns('',
         (r'^/us/$', views.american_time),
         (r'^/ca/$', views.canadian_time),
    )
    

Also you have to add the trailing slash in your JavaScript.

