Django 静态文件 404 [英] Django Static files 404

查看:34
本文介绍了Django 静态文件 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法显示静态文件.我尝试了各种设置和目录配置等,但它们只是显示为 404.我安装了 debug_toolbar,所以知道 STATIC_URL 正在到达我的请求上下文.

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.

显示/static的目录结构(我也把目录放在meals app文件夹和users里面,只是为了试试看.

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(一些重要的设置,但我已经尝试过其他各种设置):

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'

在 base.html 中呈现

In base.html rendered

    <link rel="stylesheet" href="/static/css/bootstrap.min.css">

有什么想法吗?谢谢

推荐答案

这是 django for windows 中静态/媒体/模板访问的工作解决方案,

This is the working solution for static/media/template access in django for windows,

settings.py

settings.py

import os.path

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = ( os.path.join('static'), )

这篇关于Django 静态文件 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆