2

I try everthing but i cant find solution. My Django app is cant find .css .js and media images.

All files giving 404 error

My settings file;

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

DEBUG = False

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

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

My url file;

urlpatterns = [
    path('admin/', admin.site.urls),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('', include("wallpapers.urls")),
    path('', views.index, name="index"),
    path('search/', views.search, name="search"),
    path('wallpapers/<slug:slug>/', views.tagged, name="tagged"),

]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

my base.html;

<head>
    {% load static %}
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{% block title %}title {% endblock %}</title>
    <meta name="description" content="{% block description %}  {% endblock %}">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=11"/>

    <link rel="shortcut icon" href="{% static 'img/favicon.ico' %}">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
          integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
    <link href="{% static 'css/style.css' %}" rel="stylesheet"   >

    <script src="{% static 'js/custom.js' %}"></script>
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
            integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
            integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
            crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
            integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
            crossorigin="anonymous"></script>

</head>

im using pycharm ide and django 3.0.3

when i turn debug = true everthing going fine...

Aytek
  • 224
  • 4
  • 16
  • 1
    did you run `python manage.py collectstatic`? > https://docs.djangoproject.com/en/3.0/ref/contrib/staticfiles/#collectstatic – j-i-l Feb 21 '20 at 20:06
  • Yes i did. Create staticfiles folder but i still take 404 error – Aytek Feb 21 '20 at 20:20
  • Django does not [serve static files in production mode](https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/#serving-static-files-in-production). Have you configured your web server to serve static files? – solarissmoke Feb 22 '20 at 02:36
  • manage.py runserver --insecure go to question https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail – Aleksey Mikhailov May 12 '21 at 18:43

0 Answers0