1django get static文件错误
错误附近必有解决办法
如果无法获取静态文件点击下面网址有解决办法
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ]
点击上面网址进入设置就完成了
文件夹为 static & templates 若保存在app中则下面要添加app路径
放到项目根目录则不需要添加app路径
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, 'main_app/templates/')],#后面为网页文件夹路径
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"builtins": [
"django.templatetags.static"
]
},
},
]