简体   繁体   English

django 找不到静态文件

[英]django cannot find static files

I am building login page application.我正在构建登录页面应用程序。 Intended login page application shown in below link.以下链接中显示的预期登录页面应用程序。 This login page has two images and alignment done using css and other files in django.此登录页面有两个图像,并使用 css 和 django 中的其他文件完成对齐。 When I run django server I am able to see login textboxes and static text labels, but not images and alignments is not proper, path for which is fetched from STATIC_URL or STATIC_ROOT in settings.py.当我运行 django 服务器时,我能够看到登录文本框和静态文本标签,但不能看到图像和对齐方式不正确,其路径是从 settings.py 中的 STATIC_URL 或 STATIC_ROOT 获取的。

When I run the serer I am seeing error like this当我运行 serer 时,我看到了这样的错误

 [10/Mar/2020 20:18:41] "GET / HTTP/1.1" 302 0 [10/Mar/2020 20:18:41] "GET /login/?next=/ HTTP/1.1" 200 2607 [10/Mar/2020 20:18:41] "GET /login/static/dau_gui_app/fontawesome-free-5.3.1-web/css/all.min.css HTTP/1.1" 404 141 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/style.css HTTP/1.1" 404 102 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/w3.css HTTP/1.1" 404 99 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/bootstrap.min.css HTTP/1.1" 404 110 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/dataTables/datatables.css HTTP/1.1" 404 118 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/dataTables/jQuery-3.3.1/jquery-3.3.1.js HTTP/1.1" 404 132 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/dataTables/datatables.js HTTP/1.1" 404 117 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/images/logo.png HTTP/1.1" 404 108 [10/Mar/2020 20:18:41] "GET /static/dau_gui_app/images/alstom_logo.png HTTP/1.1" 404 115

My login.html looks like this:我的 login.html 看起来像这样:

 {% load i18n %} {% load admin_static %}{% load firstof from future %}<!DOCTYPE html> <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="static/dau_gui_app/fontawesome-free-5.3.1-web/css/all.min.css"> <link rel='shortcut icon' type='image/x-icon' href='/static/dau_gui_app/images/favicon.ico' /> <link rel="stylesheet" href="/static/dau_gui_app/style.css"> <link rel="stylesheet" href="/static/dau_gui_app/bootstrap.min.css"> <link rel="stylesheet" href="/static/dau_gui_app/w3.css"> <link rel="stylesheet" href="/static/dau_gui_app/dataTables/datatables.css"> <script type="text/javascript" src="/static/dau_gui_app/dataTables/jQuery-3.3.1/jquery-3.3.1.js"></script> <script type="text/javascript" src="/static/dau_gui_app/dataTables/datatables.js"></script> <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static 'admin/css/base.css' %}{% endblock %}" /> {% block extrastyle %}{% endblock %} <title> {% block title %}Login{% endblock %} </title> </head> {% load i18n %} <body id="login_page"> <DIV style="margin-left:auto;margin-right:auto;padding-top:100px;display:block;width:30%"> <DIV id="login_box"> <table id="logon_box_table" > <!-- Title Bar --> <TR > <TD colspan='2' > <DIV id='login_box_title'> Login </DIV> </TD> </TR> <!-- login --> <TR > <TD > <div id= "logon-container" > <img src="/static/dau_gui_app/images/logo.png" alt=""> <div id="alstom-logo-container"> <img src="/static/dau_gui_app/images/alstom_logo.png" alt="" style="width: 90px; height: 18px;"> </div> <div id="version-container" >Software Version: 4.0</div> </div> </TD> <TD style="width: 490px; height: 18px;"> {% block content %} <form id="loginForm" method="post"> {% csrf_token %} {{ form.as_p }} </TD> </TR> <TR > <TD colspan='2' style="text-align:center;padding:10px"> <button style="width: 90px; height: 28px;" type="submit">Login</button> </form> {% endblock %} </TD> </TR> </TABLE> </DIV> </DIV> </body> </html>

Settings.py has this content Settings.py 有这个内容

 BASE_DIR = os.path.dirname(os.path.dirname(__file__)) STATIC_URL = '/static/' STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'dau_gui_app/static')

Login Page Image view:登录页面图片查看: 在此处输入图片说明

Page what is displayed when Django runs: Django运行时显示的页面: 在此处输入图片说明

I looked at the solution given at enter link description here which didnt help me.我查看了此处输入链接描述中给出的解决方案,但对我没有帮助。 please let me know if I am missing something and why Images are not shown in login page.如果我遗漏了什么以及为什么图像没有显示在登录页面中,请告诉我。

@all, I am able to resolve this issue by setting DEBUG=True as it was not gone for production and doing some updates in local. @all,我可以通过设置 DEBUG=True 来解决这个问题,因为它没有用于生产并在本地进行一些更新。 Not sure really how it impacts.不确定它是如何影响的。 But it worked for me when I set DEBUG=True in settings.py但是当我在 settings.py 中设置 DEBUG=True 时它对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM