[英]could not find js files in Django project
I used python 3.7 in windows 10 to create a Django project.我在 Windows 10 中使用 python 3.7 创建了一个 Django 项目。 setting.py:
设置.py:
STATIC_URL = '/static/'
LOGIN_URL = '/login'
LOGIN_REDIRECT_URL = '/'
I used superuser to create some normal user.我使用超级用户创建了一些普通用户。 But the normal user account could not login the website, and in the power shell, the below error occurs:
但是普通用户无法登录网站,并且在power shell中出现以下错误:
[02/Nov/2020 13:33:03] "POST /login/?next=/ HTTP/1.1" 200 14278 Not Found: /login/vendor/fontawesome-free/css/all.min.css [02/Nov/2020 13:33:04] "GET /login/vendor/fontawesome-free/css/all.min.css HTTP/1.1" 404 19761 Not Found: /login/vendor/jquery/jquery.min.js [02/Nov/2020 13:33:04] "GET /login/vendor/jquery/jquery.min.js HTTP/1.1" 404 19713 Not Found: /login/vendor/bootstrap/js/bootstrap.bundle.min.js [02/Nov/2020 13:33:04] "GET /login/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 19777 [02/Nov/2020 13:33:19] "POST /login/?next=/ HTTP/1.1" 200 14278 Not Found: /login/vendor/bootstrap/js/bootstrap.bundle.min.js [02/Nov/2020 13:33:19] "GET /login/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 19777 Not Found: /login/vendor/jquery/jquery.min.js Not Found: /login/vendor/fontawesome-free/css/all.min.css [02/Nov/2020 13:33:19] "GET /login/vendor/fontawesome-free/css/all.min.css HTTP/1.1" 404 19761 [02/Nov/2020 13:33:19] "GET /login/vendor/jquery/jquery.min.js HTTP/1
[02/Nov/2020 13:33:03] "POST /login/?next=/HTTP/1.1" 200 14278 未找到:/login/vendor/fontawesome-free/css/all.min.css [02/Nov /2020 13:33:04] “GET /login/vendor/fontawesome-free/css/all.min.css HTTP/1.1” 404 19761 未找到:/login/vendor/jquery/jquery.min.js [02/ Nov/2020 13:33:04] "GET /login/vendor/jquery/jquery.min.js HTTP/1.1" 404 19713 未找到:/login/vendor/bootstrap/js/bootstrap.bundle.min.js [02 /Nov/2020 13:33:04] "GET /login/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 19777 [02/Nov/2020 13:33:19] "POST /login /?next=/ HTTP/1.1" 200 14278 未找到:/login/vendor/bootstrap/js/bootstrap.bundle.min.js [02/Nov/2020 13:33:19] "GET /login/vendor/bootstrap /js/bootstrap.bundle.min.js HTTP/1.1" 404 19777 未找到:/login/vendor/jquery/jquery.min.js 未找到:/login/vendor/fontawesome-free/css/all.min.css [02/Nov/2020 13:33:19] "GET /login/vendor/fontawesome-free/css/all.min.css HTTP/1.1" 404 19761 [02/Nov/2020 13:33:19] "GET /login/vendor/jquery/jquery.min.js HTTP/1 .1" 404 19713 Not Found: /login/vendor/jquery/jquery.min.js [02/Nov/2020 13:33:19] "GET /login/vendor/jquery/jquery.min.js HTTP/1.1" 404 19712 Not Found: /login/vendor/bootstrap/js/bootstrap.bundle.min.js [02/Nov/2020 13:33:19] "GET /login/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 19776
.1" 404 19713 未找到:/login/vendor/jquery/jquery.min.js [02/Nov/2020 13:33:19] "GET /login/vendor/jquery/jquery.min.js HTTP/1.1" 404 19712 未找到:/login/vendor/bootstrap/js/bootstrap.bundle.min.js [02/Nov/2020 13:33:19]“GET /login/vendor/bootstrap/js/bootstrap.bundle.min。 Node.js HTTP/1.1" 404 19776
But I have checked that I do have their files in static folder:但我已经检查过我的静态文件夹中确实有他们的文件:
I have tried to run python manage.py collect static but the error occurs:我试图运行 python manage.py collect static 但出现错误:
raise ImproperlyConfigured("You're using the static files app " django.core.exceptions.ImproperlyConfigured: You're using the static files app without having set the STATIC_ROOT setting to a
filesystem path.
文件系统路径。
enter image description here enter image description here在此输入图片说明 在此输入图片说明
login.html {% load static %} login.html {% 加载静态 %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>{% block title %}Login{% endblock %}</title>
<!-- Custom fonts for this template-->
<link href="{% static 'vendor/bootstrap/css/bootstrap.css' %}" rel="stylesheet" type="text/css">
<link href="{% static 'vendor/fontawesome-free/css/all.min.css' %}" rel="stylesheet" type="text/css"/>
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
rel="stylesheet">
<!-- Custom styles for this template-->
<link rel="stylesheet" type="text/css" href="{% static 'css/sb-admin-2.css' %}"/>
</head>
<body class="bg-gradient-primary">
<div class="container">
<!-- Outer Row -->
<div class="row justify-content-center">
<div class="col-12">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-8 d-none d-lg-block bg-login-image"></div>
<div class="col-lg-4">
<div class="p-5">
<div class="text-center pb-5">
<img src="{% static 'image/logo.png' %}" height="60px">
</div>
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
</div>
<form class="user" method="post">
{% csrf_token %}
<div class="form-group">
<input class="form-control form-control-user" name="username" aria-describedby="emailHelp"
placeholder="Username">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-user" name="password"
placeholder="Password">
</div>
<div class="form-group">
<div class="custom-control custom-checkbox small">
<input type="checkbox" class="custom-control-input" id="customCheck">
<label class="custom-control-label" for="customCheck">Remember Me</label>
</div>
</div>
<button type="submit" class="btn btn-primary btn-user btn-block">
Login
</button>
</form>
<hr>
<div class="text-center">
<a class="small" href="forgot-password.html">Forgot Password?</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="{% static 'vendor/jquery-easing/jquery.easing.min.js' %}"></script>
<!-- Custom scripts for all pages-->
<script src="{% static 'js/sb-admin-2.min.js' %}"></script>
</body>
</html>
Please follow steps here to make static files work.请按照此处的步骤使静态文件工作。 Judging from errors you posted, I guess that following is misconfigured:
从您发布的错误来看,我猜以下配置错误:
STATIC_URL='/login/'
.STATIC_URL='/login/'
。 Typically it should be set to STATIC_URL = '/static/'
STATIC_URL = '/static/'
static
folder within one of your apps.static
文件夹中。 Ie if you have an app named bms
, then put your static files to bms/static
folder.bms
的应用程序,则将您的静态文件放到bms/static
文件夹中。 Django provides helpful findstatic command to help you understand where it is looking for given static file, for example: python manage.py findstatic -v3 js/msp/table_header.js
python manage.py findstatic -v3 js/msp/table_header.js
runserver
command) and only if you set DEBUG=True
in settings.runserver
命令)并且仅当您在设置中设置DEBUG=True
,django 才会自己提供静态文件。 For serving static files in production environment, please see this doc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.