0

I created a simple project in Django but static files(CSS) not working.

settings.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.portfolio),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

HTML file

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="{% static 'portfolio.css' %}">
</head>
<body>
    <h1>hello world</h1>
</body>
</html>

picture of the project directory

picture of the project directory.

blog is app and my_site is a project.

0

1 Answer 1

1

try adding

os.path.join(BASE_DIR, "my_site/static")

to STATICFILES_DIRS

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    os.path.join(BASE_DIR, "my_site/static")
]

OR

place the static folder in the root my_site folder

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.