2016-03-19 19 views
1
ben açısal js Bir Django görünümüne bir post isteği gönderiyorum

verir ama bana 500 (dahili sunucu hatası) verir.Mesaj isteği 500 iç sunucu hatası

Bu benim açısal dosyasıdır:

var app = angular.module('myApp', []) 
app.config(function($interpolateProvider, $httpProvider){ 
$interpolateProvider.startSymbol('{[{').endSymbol('}]}'); 
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; 
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; 
}); 
app.controller('myCtrl', ['$scope', '$http', function ($scope, $http){ 
var details = { 
length : $scope.length, 
breadth : $scope.breadth, 
height : $scope.height, 
weight : $scope.weight, 
country : $scope.country, 
itemType : $scope.itemType 
} 
var theJSON = JSON.stringify(details); 
$http({ 
     method : 'POST', 
     url  : '/interApp/calc/', 
     data : $.param(theJSON), 
     headers : {'Content-Type': 'data:application/json;charset=utf-8;'+ encodeURIComponent(theJSON) }, 

    }).success(function(data) { 
     console.log(theJSON); 
    }) 

    } 
}]) 

ve bu django görünümüdür:

from django.http import Http404 
from django.http import HttpResponse 
from django.shortcuts import render_to_response 
from .models import Countries,CourierCompany,Zones,Weight 
from django.core.context_processors import csrf 

def rate_calculator(request): 
    if request.method == "POST": 
     ////code goes here... 

ve benim urls.py dosyasıdır:

from django.conf.urls import url 
from . import CostView 
urlpatterns = [ 
    url(r'^calc/', views1.rate_calculator, name='rate_calculator'), 
] 

ama bana verir konsol penceresinde hata:

SONRASI http://127.0.0.1:8000/interApp/calc/ 500 (Dahili sunucu hatası) json ederek Django işlevi veri okumak için

+0

Bence, bunu kullanarak bunu elde Yayınınız isteği verileri var eğer alışkanlık .. Hatası ile talep, bu POST izlerseniz ı may düşünüyorum beni tam hata ne olduğunu bildirmek 'veriler: - ayarlarında' DEBUG = TRUE ayarlamak ve hatayı gözlemlemek theJSON, 'başarısız olursa olsun –

+0

deneyin yeterlidir. Veya, kurulum ayarlarınız varsa, hatanın ne olduğunu araştırın. –

+1

aynı hata da var postacı kullanarak veri göndermek ve görmek için orada – alecxe

cevap

0

deneyin, aynı kullanarak postacı

def rate_calculator(request): 
    if request.method == "POST": 
     loadedJsonData = json.loads(request.body) 
     length = loadedJsonData.get('length') 
deneyin
+0

Ben Debug = True var ve tarayıcımın konsol penceresinde 500 hatası alıyorum ve veri okumaya yardımcı olmuyor. –

+0

, bu verileri postacıya aynı isteği vermek için kullanır ve ardından hatanın tam olarak ne olduğunu görür. Verileri okuduktan sonra kodunuzda bir hata olabilir. –

0

Kişisel Hata Temizle değil ve URL de yanlış geliyor düşünüyorum .. Yani senin açısal yazı gerçekten görüşlere çarptıysa? isteğinizi görüntüleyenler altında yazdırmak için Bu gibi

def rate_calculator(request): 
    print 'request',request 

onay POST içerik: ...... ve sadece ithalat yoluyla .. ayrıca bu Traceback deneyin

from traceback import format_exc 

ve görünümler altında bu baskı deyimi koymak,

Bundan önce, bu açısal POST yöntemini denemek
print 'Error report', repr(format_exc()) 

,

$http.post('/your url/', { 
    data: details, 
}).success(function(response) { 
    console.log('your console') 
}) 

Sonra

data = json.loads(request.body) 
+0

da yardımcı olmuyor. –

İlgili konular