【问题标题】:Parent directory symbol not working in html父目录符号在html中不起作用
【发布时间】:2021-09-09 14:13:39
【问题描述】:
<meta charset="utf-8">
   <title>Exam Page</title>
    <link rel="stylesheet" href="../../../static/css/teststyle.css">
 </head>

我在考试文件夹中使用此代码,我想转到父目录,所以我使用了 ../../ 但它显示以下错误

未找到:/exam/static/css/teststyle.css

【问题讨论】:

    标签: python django directory atom-editor web-development-server


    【解决方案1】:

    在您的模板顶部添加{% load static %} 并添加您的CSS,您可以使用{% static 'css/teststyle.css' %}

    {% load static %}
    
        <meta charset="utf-8">
        <title>Exam Page</title>
        <link rel="stylesheet" href="{% static 'css/teststyle.css' %}">
    </head>
    
    

    在你的主urls.py添加

    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    

    并在您的settings.py 中添加

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

    【讨论】:

    • 很高兴它有帮助!请将此答案标记为accepted
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多