简体   繁体   English

使用 django 时无法链接 html

[英]can't get html to link while using django

If anyone can help me on why my html wont link with my css that would be awesome!如果有人可以帮助我解释为什么我的 html 不会与我的 css 链接,那就太棒了! Thanks!谢谢! I'm using Django 3.0.2 to make a website for a resume and I have already rooted my static files and that didn't seem to do anything.我正在使用 Django 3.0.2 制作简历网站,并且我已经植根了我的静态文件,但似乎没有做任何事情。 I have tried stopping and running my server multiple times as well as find solutions online but everyone is using an older version or their solutions don't help.我曾多次尝试停止和运行我的服务器以及在线查找解决方案,但每个人都使用旧版本或他们的解决方案无济于事。

HTML: HTML:

<head>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static '/base/styles.css' %}">
</head>
<body>
    this is a test
    <div class="container">
        <header>
            {% include 'navbar.html' %}
        </header>
    </div>
</body>

CSS: CSS:

body {
    background-color: rgb(82, 70, 70);
}

.container{
    background-color: rgb(128, 199, 172);
}

.navbar{
    background-color: rosybrown;
}

SETTINGS:设置:

STATICFILES_DIR = [
    os.path.join(BASE_DIR, 'static'),
    '/pydir/mysite/static',
]

STATIC_ROOT = '/pydir/mysite/static'

STATIC_URL = '/static/'

and I made sure that staticfiles and admin where in the installed apps.我确保 staticfiles 和 admin 在安装的应用程序中的位置。

FOLDER STRUCTURE:文件夹结构:

├───mysite
│   │   asgi.py
│   │   settings.py
│   │   urls.py
│   │   wsgi.py
│   │   __init__.py
│   │   
│   └───__pycache__
│           settings.cpython-37.pyc
│           urls.cpython-37.pyc
│           wsgi.cpython-37.pyc
│           __init__.cpython-37.pyc
│           
├───pages
│   │   admin.py
│   │   apps.py
│   │   models.py
│   │   tests.py
│   │   views.py
│   │   __init__.py
│   │   
│   ├───migrations
│   │       __init__.py
│   │       
│   └───__pycache__
│           views.cpython-37.pyc
│           __init__.cpython-37.pyc
│           
├───projects
│   │   admin.py
│   │   apps.py
│   │   models.py
│   │   tests.py
│   │   views.py
│   │   __init__.py
│   │   
│   ├───migrations
│   │   │   0001_initial.py
│   │   │   __init__.py
│   │   │   
│   │   └───__pycache__
│   │           0001_initial.cpython-37.pyc
│   │           __init__.cpython-37.pyc
│   │           
│   └───__pycache__
│           admin.cpython-37.pyc
│           models.cpython-37.pyc
│           __init__.cpython-37.pyc
│           
├───static
│   ├───base
│   │       styles.css
│   │       
│   └───images
└───templates
        home.html
        navbar.html

Found the issue!发现问题! it was the folder order.这是文件夹顺序。 I had the static folder on the outside of my apps because I was treating it like the templates folder but I had to move it to an app for it to work.我的应用程序外部有静态文件夹,因为我将它视为模板文件夹,但我必须将其移动到应用程序才能工作。 Thanks for the help tho!感谢您的帮助!

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

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