Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

I am unable to load static files in django although i have done everything

enter image description herein my settings.py file i did

STATICFILES_LOCATION='static'
STATIC_URL = '/static/'
STATICFILES_DIR=[
os.path.join(BASE_DIR,'Kevin/static')
]
STATIC_ROOT='static'

but in my templates i am unable to load the files the template folder is in root directory whereas static folder is in django root folder named as Kevin which is also in that base folder in my html template i did the

{% load static %}

i am sharing some code of my template as well so you can have a look enter image description here {% load static %}

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">

<title>Kevin - Dashboard</title>

<!-- Custom fonts for this template-->
<link href="{% static 'vendor/fontawesome-free/css/all.min.css'%}" rel="stylesheet" type="text/css">
<link
    href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
    rel="stylesheet">

<!-- Custom styles for this template-->
<link href="{%static 'css/sb-admin-2.min.css'%}" rel="stylesheet">

enter image description here

question from:https://stackoverflow.com/questions/65914965/i-am-unable-to-load-static-files-in-django-although-i-have-done-everything

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to set a static URL in urls.py also

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
   .....
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Read this https://docs.djangoproject.com/en/3.1/howto/static-files/#serving-static-files-during-development


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...