N
N
nickname19902016-07-12 13:30:07
Django
nickname1990, 2016-07-12 13:30:07

Why can't it find the file and give a 404?

I'm trying to send a post request, but for some reason I'm getting a 404.
What's wrong?
js code:

var doc = document;


function jax(url,post,post_data) 
{ 
   
   var return_data = 0;
   var hr = new XMLHttpRequest();
   var uri = url;
   hr.open("POST", uri, true);
   hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   
   
   var post = post;
   var vars = post + post_data;
   //console.log(vars);
   
   hr.onreadystatechange = function() 
   {
         
         if(hr.readyState == 4 && hr.status == 200) 
         {
            var return_data = hr.responseText;
          console.log(return_data)
     }
     
     
  
   }
    
   hr.send(vars);
   
}
var adres = 'hello';

doc.getElementById('go').onclick = function()
{
      jax('http://127.0.0.1:8000/search/',"go=",adres);
}

python code(view)
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.shortcuts import render_to_response



def hello(request):
    return render_to_response('test.html')
    
    
def search(request):
    if 'go' in request.POST:
        message = 'You searched for: %r' % request.POST['go']
    else:
        message = 'You submitted an empty form.'
    return HttpResponse(message)

python code urls.py
from django.conf.urls import url
from django.contrib import admin
from django_test.views import hello

urlpatterns = [
    
    url(r'^hello/$', hello),
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tema_sun, 2016-07-12
@tema_sun

Where is urls.py?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question