2017-06-12 158 views
0

我在S3文件夾中運行Html文件,在HTML文件中運行/打開HTML文件時出現AJAX調用I我正在低於錯誤。加載資源失敗:服務器響應狀態爲500(內部服務器錯誤)Django

無法加載資源:服務器按照500的狀態迴應(內部服務器錯誤)

從S3桶JS文件我的代碼

<script type="text/javascript"> 

$(document).ready(function() { 

    $.get("https://52.221.186.121/email_view/6/", function (data) { 
     console.log(JSON.stringify(data)); 
     email_otp = JSON.stringify(data); 
     $("#btnSubmit").click(function() { 
      var input_value = $('#entered_otp').val(); 
      alert(input_value); 
      alert(email_otp); 
      if (email_otp == input_value) { 
       alert('matches'); 
       $('.modal').removeClass('show'); 

      } 
      else { 
       alert('not matching'); 

       window.location = "https://awslocation.com/mobile/index.html"; 

      } 
     }); 
    }); 


}); 

對應views.py代碼

def email_view(request, id): 
    course = get_object_or_404(CourseWare, pk=id) 
    user = UserProfile.objects.get(user__id=request.user.id) 
    myorder = MyOrder.objects.get_or_create(buyer=user, course=course) 
    if myorder: 
     sms_otp = randint(10000, 100000) 
     user = UserProfile.objects.get(user__id=request.user.id) 
     email = user.user.email 
    body = '''Dear User, \n Please Enter the OTP to view the Course. 
              \n \n OTP : %s \n \n Thanks,''' % (
     sms_otp) 
     email = EmailMessage('Course Ware OTP', body, to=[email]) 
     email.send() 
    if request.is_ajax(): 
     return HttpResponse(json.dumps(sms_otp), content_type="application/json") 

taceback

27.6.180.134 - - [12/Jun/2017:17:24:40 +0000] "GET /email_view/6/ HTTP/1.1" 500 38 "url_from_html_page_in_s3_bucket" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" 
27.6.180.134 - - [12/Jun/2017:17:53:59 +0000] "GET /email_view/6/ HTTP/1.1" 500 38 "url_from_html_page_in_s3_bucket" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" 

urls.py

url(r'^email_view/(?P<id>[-\w]+)/$', 'admin.views.course_ware.email_view', 
    name='email_view' 
    ), 
+0

你有追溯嗎?它應該在日誌 –

+0

這裏是我的追溯。我編輯了我的問題。 –

+0

請問您可以添加urls.py嗎? – WPedrak

回答

0

時要求不是Ajax調用你不返回任何東西。

嘗試增加:

return HttpResponse('It failed') 

email_view功能的盡頭並檢查它是否失敗。

相關問題