[Answered ]-Django static css is not loading on page

1👍

settting.py:

STATIC_URL = '/static/'

Only one {% load static %} is enough in your html code:

<!DOCTYPE html>
{% load static %}
  

You have to Copy and Plast your STATIC files (Js, CSS, …) in your templates.

It will look like that :

djangoAjaxApp
|_migrations
|_templates
|     |_djangoAjaxApp
|           |_css_practice.html
|_static
    |___djangoAjaxApp (directory with the same App name)
         |_(here all your static file)
            

Your HTML will look like this:

<link type="text/css" rel="stylesheet" href"{% static 'djangoAjaxApp\ok.css' %}">

views.py:

# css practice

def cssRender(request):

    return render(request, "djangoAjaxApp/css_practice.html")

urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.cssRender, name='cssRender'),
        ]

djangoAjax urls.py:

from django.conf import settings
from django.contrib import admin
from django.urls import path

urlpatterns = [
    # ... the rest of your URLconf goes here ...
    ]

0👍

Could you please try it.

from django.contrib.staticfiles.urls import staticfiles_urlpatterns


if settings.DEBUG:
    urlpatterns += staticfiles_urlpatterns()
👤Mamed

0👍

Just to remind you of it, have you tried hard refresh on your browser? I used to miss this when I was a beginner. (You can do it in chrome with ctrl+shift+r).

Leave a comment