0

Why I am receiving files can't be found error while loading all the static files even after setting everything correctly.

ERROR

enter image description here

CODE:

Admin Section

- settings.py

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

- urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('Welcome.urls')),
    path('auth/', include('Authentication.urls')),
    path('ad/', include('Ads.urls')),
    path('user/', include('UserDashboard.urls')),
    path('admin/', include('AdminDashboard.urls')),
]

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

Apps Section

- template

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

- Folder Structure

enter image description here

Muhammad Asim
  • 161
  • 2
  • 9
  • 2
    You told it that the `/static/` URL should be routed to the `BASE_DIR`. I think you want `BASE_DIR + '/static'`. – Tim Roberts Sep 11 '21 at 18:33
  • The error which is generated after this, `STATIC_ROOT = os.path.join(BASE_DIR + '') TypeError: unsupported operand type(s) for +: 'WindowsPath' and 'str'` – Muhammad Asim Sep 11 '21 at 19:20

1 Answers1

1

You get this error because the Django project searches your static folders in the wrong place.

This will work:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
black
  • 799
  • 1
  • 9
  • 23