Django静态文件404 [英] Django Static files 404
问题描述
我无法让我的静态文件出现。我已经尝试过各种设置和目录配置等等,但它们只是变成404。我已经安装了debug_toolbar,所以知道STATIC_URL正在达到我的请求上下文。
目录结构显示/静态(我还将目录放在餐食应用文件夹中,用户,只是为了尝试一下。
/ mealmate
/ mealmate
/ meals
/ static
/ css
/bootstrap.min.css
/ templates
/ users
Settings.py(一些重要的设置,虽然我已经尝试了各种各样的):
MEDIA_ROOT = os.path.join(PROJECT_PATH,'media /')
STATIC_URL ='/ static /'
INSTALLED_APPS =(
'django .contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib .messages',
'django.contrib.staticfiles',
)
WSGI_APPLICATION ='mealmate.wsgi.applicat $'
$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ pre> < link rel =stylesheethref =/ static / css / bootstrap.min.css>
任何想法?
谢谢
这是django中针对windows的静态/媒体/模板访问的工作解决方案,
settings.py
import os.path
STATIC_ROOT =''
STATIC_URL ='/ static /'
STATICFILES_DIRS =(os.path.join('static'),)
I can't get my static files to come up. I've tried various settings and directory configurations and so on, but they just turn up as 404s. I have debug_toolbar installed so know that STATIC_URL is reaching my request context.
Directory structure showing /static (I have also placed the directory inside of the meals app folder, and users, just to try it out.
/mealmate
/mealmate
/meals
/static
/css
/bootstrap.min.css
/templates
/users
Settings.py (a few important settings though I've experimented with a variety of other ones):
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media/')
STATIC_URL = '/static/'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
WSGI_APPLICATION = 'mealmate.wsgi.application'
In base.html rendered
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
Any ideas? Thanks
This is the working solution for static/media/template access in django for windows,
settings.py
import os.path
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join('static'), )
这篇关于Django静态文件404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!