Django没有看到静态文件 [英] Django doesn't see static files
本文介绍了Django没有看到静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,事实是django根本无法识别静态文件.不管我尝试了什么,都行不通.我尝试将全局搜索方式更改为css文件的直接url,但这似乎都不起作用.
So the thing is that django simply can't recognize the static files. No matter what have I tried it just doesn't work. I tried changing the from global searching way to a direct url of the css file, none of this seems to work.
我的项目的结构如下:
这是我的代码:
DEBUG = True
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
STATIC_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
from django.contrib import admin
from django.urls import path
from something.views import *
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Monkeys</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/file.css' %}"/>
</head>
可以在互联网上的任何主题中找到答案,所以希望您能提供帮助.
Could find the answer in any topic on the internet so I'm hoping you could help.
推荐答案
Currently you have a typo - STATIC_DIRS instead of STATICFILES_DIRS, so collectstatic is not configured at all currently.
修复它,然后再次运行 collectstatic
.
Fix it, then run collectstatic
again.
这篇关于Django没有看到静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文