0
votes

static folder path correct and it was all working before migration.

  • index.html
{%load staticfiles%}
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="{% static "css/mycss.css"%}"/>
        <title>My first Django App</title>
    </head>
    <body>
    <h1>{{somthin}}</h1>
    <img src="{% static 'images/zoro.jpg'%}" alt="Oops!No Image">

    </body>
</html>

after python manage.py runserver in terminal static files are showing 404 error.

1

1 Answers

1
votes

make sure all these configuration you have in your settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

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

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static")

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media")

and in main urls.py

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

and use {% load static %} tag in templates, also if you use double quote outside curly brackets, use single quote inside

<link rel="stylesheet" href="{% static 'css/mycss.css' %}"/>