django 为什么我的控制台显示我的html文件的编码?

uqzxnwby  于 2023-07-01  发布在  Go
关注(0)|答案(1)|浏览(108)

我能够使用数量增量,但我不小心撤销了我的工作,结果是这样的,请有人帮助我>:(
the console print out my base.html coding and does not increase the quantity

(base.html)

<!DOCTYPE html>
<html lang="en">
   {% load static %}
   <head>
      <!-- Required meta tags -->
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <!-- Bootstrap CSS -->
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
      <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>   
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
      <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
      <script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script> 
      <title>Python World</title>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      <style>
         nav{
         background-color: white;
         }
         .one-edge-shadow {
         box-shadow: 0 8px 2px -5px rgb(246, 245, 245);
         }
         .display-8{
         font-weight: 200;
         font-size: 30px;
         }
         .badge {
         padding-left: 9px;
         padding-right: 9px;
         -webkit-border-radius: 9px;
         -moz-border-radius: 9px;
         border-radius: 9px;
         }

         .label-warning[href],
         .badge-warning[href] {
         background-color: #c67605;
         }
         #lblCartCount {
            font-size: 15px;
            background: #ff0000;
            color: #fff;
            padding: 0 5px;
            vertical-align: top;
            margin-left: -17px; 
         }
         .btn-circle.btn-sm {
            width: 25px;
            height: 25px;
            padding: 7px;
            border-radius: 14px;
            font-size: 12px;
            text-align: center;
            font-weight: bold;
         }
      </style>
      <script>
      function cartpage()
      {
         window.location.href="{% url 'cartpage' %}"
      }

      </script>
   </head>
   <body>
      <!-- navbar -->
      <nav class="one-edge-shadow sticky-top navbar navbar-expand-lg navbar navbar-dark bg-primary">
         <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
         <span class="navbar-toggler-icon"></span>
         </button>
         <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
               <li class="nav-item active">
                  <a class="nav-link" href="/">Home <span class="sr-only"></span></a>
               </li>
            </ul>
            <form class="d-flex">
               <input class="form-control me-2 mr-2" type="search" placeholder="Search" aria-label="Search" name="query">
               <button class="btn btn-warning mr-4" type="submit">Search</button>
            </form>
            <ul class=" navbar-nav my-2 my-lg-0">
 
               <!--<li class="nav-item active">
                  <a class="nav-link" href="#"><span class="badge bg-danger">{{totalitem}}</span> Cart </a>
                  <span class="sr-only">(current)</span></a>
               </li>-->
               <li class="nav-item active" style="margin-right:20px;">
               <button class="nav-link fa" onClick="cartpage()" style="font-size:25px">&#xf07a;</button>
               <span class='badge badge-warning' id='lblCartCount'>{{total_quantity}}</span>
               </li>
            </ul>
         </div>
      </nav>
      {% block content %}{% endblock %}

      <script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
      
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
         integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
         crossorigin="anonymous"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
         integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
         crossorigin="anonymous"></script>
   </body>
</html>
(cartpage.html)

{% extends 'base.html' %}
{% load static %}
{% block title %}Cart{% endblock title %}
{% block content %}

<div class="container">
    <div class="border rounded p-4 m-4">
        <p class="display-4 pl-4 ml-4">Shopping Cart</p>
        <hr>
        
        <table class="table table-fixed">
            <thead class="thead-dark">
                <tr>
                    <th></th>
                    <th class="w-5">Image</th>
                    <th>Product</th>
                    <th>Quantity</th>
                    <th>Price</th> 
                </tr>
            </thead>
        
            <tbody>
                <tr>
                {% for cart in cart %}
                    <td><ion-icon name="close-outline"></ion-icon></td>
                    <input type="hidden" name="prod_id" value="{{product.ProdID}}" id="prod_id">
                    <td class="w-5"><image src="{{ cart.product.ProdPic.url }}" style="height:80px; width:65px;" class="rounded-circle"></td>
                    <td>{{cart.product.ProdName}}</td>
                    
                       
                        <td>
                            
                            <input type="button" pid="{{cart.product.ProdID}}" class="minus-cart btn btn-light btn-circle btn-sm" value="-">
                            <span id="quantity" min="1">{{ cart.item_qty }}</span>
                            <input type="button" pid="{{cart.product.ProdID}}" class="plus-cart btn btn-light btn-circle btn-sm" value="+" >
                        
                        </td>
                            
                    <td>RM{{cart.product.ProdPrice}}</td>
                </tr>

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
            
                <script>
                    
                    $('.plus-cart').click (function(){
                    var id=$(this).attr("pid").toString();
                    console.log(id)

                    $.ajax({
                    type : "Get",
                    data : {
                    prod_id : id
                    },
                    success:function(data){
                    console.log(data)
                    }

                    })

                    }); 

                </script>
                  
                {% endfor %}
            </tbody>
                

            <tfoot>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>Total Price :</td>
                    <td>RM9</td>
                </tr>
            </tfoot>
    </table>
            
        
        
    </div>
</div>



{% endblock %}
(this is the script in my cartpage.html) 

           <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
                <script>
                    
                    $('.plus-cart').click (function(){
                    var id=$(this).attr("pid").toString();
                    console.log(id)

                    $.ajax({
                    type : "Get",
                    data : {
                    prod_id : id
                    },
                    success:function(data){
                    console.log(data)
                    }

                    })

                    }); 

                </script>
(this is my views.py)
def cartpage(request):
    cart = Cart.objects.all()

    dict={
        'cart':cart
    } 
    return render (request,"cartpage.html",dict)

def plus_cart(request):
    product_id = request.GET['prod_id']
    product=Product.objects.get(ProdID=product_id)
    cart = Cart.objects.get(product=product)
    cart.item_qty += 1
    cart.save()

    data = {
        'item_qty' : item_qty
    }
    return JsonResponse(data)
(urls.py)

from django.urls import path
from . import views

urlpatterns = [
    path("",views.welcome,name="welcome"),
    path('homepage/',views.homepage,name="homepage"),
    path('cartpage/',views.cartpage,name='cartpage'),
    path('add_to_cart/', views.add_to_cart, name='add_to_cart'),
    path('plus_cart/',views.plus_cart,name='plus_cart')
]

我是一个学生,所以我在这方面是新。当有 AJAX 是没有功能的错误,我替换jquery脚本链接与新的和控制台将出现编码idk哪里是问题。.对不起,代码混乱!!

qfe3c7zg

qfe3c7zg1#

你不在开发工具的“控制台”标签中,你在应该显示HTML代码的源代码标签中。您可以在此页面上尝试,例如:
example
尝试进入控制台(源旁边的选项卡),看看是否输出错误或是否输出任何信息。

相关问题