Пытаюсь отправить пост запрос но почемуто выдает 404.
Что не так?
js код:
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 код(представление)
# -*- 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 код urls.py
from django.conf.urls import url
from django.contrib import admin
from django_test.views import hello
urlpatterns = [
url(r'^hello/$', hello),
]