带有源“ http://127.0.0.1:8000/static/js/bootstrap.min.js”的<script>加载失败

时间:2019-06-19 11:29:20

标签: django ajax

我收到错误消息“源“ http://127.0.0.1:8000/static/js/bootstrap.min.js的加载失败”。而且我的ajax也无法正常工作。我想删除django表单而不刷新页面

def client_delete(request, pk):
    data = {'success': False}
    client = Client.objects.get(pk=pk)
    if request.method == 'GET':
        try:
            client.delete()
            if client:
                data['success']=True
            else:
                data['success'] = False
                data['error'] = "unsuccessful!"
        except Client.DoesNotExist:
            return redirect('/NewApp/clientlist')
return JsonResponse(json.dumps(data))

在我的client_list.py文件中,

{% block javascript %}
<script src="{% static '/js/app.js' %}"></script>
<script src="{% static '/js/jquery-3.2.1.js' %}"></script>
<script src="{% static '/js/bootstrap.min.js' %}"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4           /jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.marquee@1.5.0  /jquery.marquee.min.js"></script>
{% endblock %}

<script>
document.getElementById("print").addEventListener("click", function() {
    console.log("deleted")
    alert('ok');
    var id = $(this).attr('name');
    $.ajax({
        type:'GET',
        url: 'NewApp/clientdelete' + id,
        data:{
            csrfmiddlewaretoken:   $('input[name=csrfmiddlewaretoken]').val()
        },
       success: function(data){
          if(data.success == true){
         alert("success");
       }
       }
   });
  return(false);
});

1 个答案:

答案 0 :(得分:1)

尝试使用模板中没有js开头的“ /”开头的路径。它看起来应该像{%static'js / app.js'%},并确保根据您的模板使用{%load static%}或{%load staticfiles%}。