python url not found - Accessing views.py from AJAX
<p>New to Python and Django and I'm trying to make a simple ajax call from a button click to pass certain data to my views.py, however, when I try to make a url as seen on my ajax code below, the <code>documentId.id</code> does not append unless I directly append in without the <code>"?id="</code>.</p>

<pre><code>    {%for document in documents%}
       {{document.filename}}
       &lt;input type="button" id="{{document.id}}" onclick="loadData(this)" name="load-data" value="Add"/&gt;
    {%endfor%}

 &lt;script type ="text/javascript"&gt;
    function loadData(documentId){
       $.ajax({
       url:"upload-data/load" + "?id=" + documentId.id,
       data: {'documentId': documentId},
       type: 'GET',
       success: function(){
          window.location.href = "http://127.0.0.1:8000/url/locations";
       }
    });
    }
 &lt;/script&gt;
</code></pre>

<p>This gives me then an error that says the url cannot be found. I have a line in my urls.py below:</p>

<pre><code>url(r^"upload-data/load/([0-9]+)/$', views.loadFile, name="load-data"),
</code></pre>

<p>Other than this method, I am stumped as to how I am going to extract my data to my views.py.</p>

<pre><code>def loadFile(request):
    documentId = request.GET.get('id')
    newLayer = Layer(get_object_or_404(Document, pk = documentId))
    newLayer.save()
    layers = Layer.objects.all()

    return render(request, 'url/loaded.html', { 'layers': layers})
</code></pre>

<p>The persisting error in the console would be:</p>

<blockquote>
  <p><a href="http://127.0.0.1:8000/upload-data/load/" rel="nofollow">http://127.0.0.1:8000/upload-data/load/</a>                 [HTTP/1.0 404 Not Found]</p>
</blockquote>

<p>Use something like this:</p>

<pre><code>def loadFile(request):
    documentId= request.GET.get('id', '').
    newLayer = Layer(get_object_or_404(Document, pk = documentId))
    newLayer.save()
    layers = Layer.objects.all()

    return render(request, 'url/loaded.html', { 'layers': layers})
</code></pre>

<p>And update your url as :</p>

<pre><code>    url(r^"upload-data/load/', views.loadFile, name="load-data")
</code></pre>

<p>And the script would be like :</p>

<pre><code>&lt;script type ="text/javascript"&gt;
    function loadData(documentId){
       $.ajax({
       url:"upload-data/load/?id="+ documentId.id,
       data: {'documentId': documentId},
       type: 'GET',
       success: function(){
          window.location.href = "http://127.0.0.1:8000/url/locations";
       }
    });
    }
 &lt;/script&gt;
</code></pre>

<p>Thanks.</p>

python ajax django url onclick