我有一个名为' baseu .html'的基本模板。我已经使用{% load static%}加载了静态文件.当我继承到另一个模板的javascript和CSS似乎坏了。控制台显示Refused to execute script from 'http://127.0.0.1:8000/Ticket/static/dashboard/script.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
但是第一次渲染是完美的,但是当我把它路由到另一个目录时,目录改变了,而不是调用/dashboard/style.css
路径("票/& lt; str: id>",RaiseTickets, name = ' raiseticket '),
django服务器控制台显示"GET /User_Management/vyshnav/static/dashboard/ajax.js HTTP/1.1" 404 3118
为什么路由路径包含代码如下
<!DOCTYPE html>
<html lang="en">
<head>
{% load static %}
{%block content%}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Boxicons -->
<link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'>
<!-- My CSS -->
<link rel="stylesheet" type="text/css" href="{% static 'dashboard/style.css' %}">
<script src="{% static 'dashboard/script.js' %}"></script>
<script
src="https://code.jquery.com/jquery-3.6.4.min.js"
integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8="
crossorigin="anonymous"></script>
<title>Admin Dashboard</title>
</head>
<body>
<!-- SIDEBAR -->
<section id="sidebar">
<a href="#" class="brand">
<i class='bx bxs-institution'></i>
<span class="text">{{LoggedUser.First_Name}} {{ LoggedUser.Last_Name}}</span>
</a>
<ul class="side-menu top">
<li class="active">
<a href="{% url 'home' id=LoggedUser.User_Id %}">
<i class='bx bxs-home'></i>
<span class="text">Dashboard</span>
</a>
</li>
<li>
<a href="{% url 'User_Management' id=LoggedUser.User_Id %}">
<i class='bx bxs-user'></i>
<span class="text">User Management</span>
</a>
</li>
<li>
<a href="{% url 'raiseticket' id=LoggedUser.User_Id %}">
<i class='bx bxs-wallet'></i>
<span class="text">Tickets</span>
</a>
</li>
<li>
<a href="#">
<i class='bx bxs-message-dots' ></i>
<span class="text">Chats</span>
</a>
</li>
</ul>
<ul class="side-menu">
<li>
<a href="#">
<i class='bx bxs-cog' ></i>
<span class="text">Settings</span>
</a>
</li>
<li>
<a href="{% url 'logout' %}" class="logout">
<i class='bx bxs-log-out-circle' ></i>
<span class="text">Logout</span>
</a>
</li>
</ul>
</section>
<!-- SIDEBAR -->
<!-- CONTENT -->
<section id="content">
<!-- NAVBAR -->
<nav>
<i class='bx bx-menu' ></i>
<a href="#" class="nav-link">Categories</a>
<form action="#">
<div class="form-input">
<input type="search" placeholder="Search...">
<button type="submit" class="search-btn"><i class='bx bx-search' ></i></button>
</div>
</form>
<input type="checkbox" id="switch-mode" hidden>
<label for="switch-mode" class="switch-mode"></label>
<a href="#" class="notification">
<i class='bx bxs-bell' ></i>
<span class="num">0</span>
</a>
<a href="#" class="profile">
<i class='bx bxs-user-circle'></i>
</a>
</nav>
<!-- NAVBAR -->
<!-- MAIN -->
<main>
<div class="head-title">
<div class="left">
<h1>Dashboard</h1>
<ul class="breadcrumb">
<li>
<a href="#">Dashboard</a>
</li>
<li><i class='bx bx-chevron-right' ></i></li>
<li>
<a class="active" href="#">Home</a>
</li>
</ul>
</div>
</div>
<!-- AJAX implementing -->
{%block body%}
{% endblock %}
</main>
<!-- MAIN -->
</section>
<!-- CONTENT -->
<script src="static/dashboard/script.js"></script>
<script src="static/dashboard/ajax.js"></script>
</body>
{%endblock%}
</html>
,继承的子模板是
{% extends "baseUI.html" %}
{% block body %}
<form action="" method="POST" enctype="multipart/form-data">
{%csrf_token%}
{{ form.as_p}}
{{form2.as_p}}
</form>
<button type="submit" name="submit" value={{LoggedUser.User_Id}}>Submit</button>
{%endblock%}
尝试了我所知道的一切
请在HTML文件底部更改
<script src="static/dashboard/script.js"></script>
<script src="static/dashboard/ajax.js"></script>
<script src="{% static '/dashboard/script.js' %}"></script>
<script src="{% static '/dashboard/ajax.js' %}"></script>
注释:你的问题有几点——这并不能解决所有问题。