Django静态文件未使用默认设置加载 [英] Django static files not loading with default setup

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

问题描述

因此,我安装了Bitnami Django堆栈,并启用了管理模块,并按照教程为投票"创建管理菜单.

So I installed Bitnami Django stack, and enabled the admin module, and followed the tutorial for creating an admin menu for "Polls".

但是,当我进入/admin/时,所有内容都是白色纯文本.所有的css和图片都出现404错误.

However, when I go to /admin/ everything is white plaintext. All the css and images are 404 error.

我所做的只是:

在settings.py已安装的应用中启用:

enable in settings.py installed_apps:

'django.contrib.admin',

在urls.py中未注释:

In urls.py UNcommented:

from django.contrib import admin
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),

未注释.

在settings.py中,我尝试使用默认设置,还尝试了以下方法:

In settings.py, I tried using default settings and also tried this:

MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)

似乎没有任何作用,它拒绝在/admin/media/css/等文件中找到静态文件.

Nothing seems to work, it refuses to find static files in /admin/media/css/ etc.

我确保我的Windows PATH包含django的/bin.我什至尝试包含/contrib,也无济于事.

I made sure my windows PATH has /bin of django. I even tried including /contrib, nothing helps.

我已将Django安装到:C:\ DjangoStack \ apps \ django

I have installed Django to: C:\DjangoStack\apps\django

我已将项目安装到:C:\ Users \ dexter \ BitNami DjangoStack项目\ Alpha然后输入:localhost/Alpha/admin进入管理员.

I have installed my project to: C:\Users\dexter\BitNami DjangoStack projects\Alpha and I type: localhost/Alpha/admin to go to admin.

推荐答案

在我重新阅读您的问题并最终抓住最后一行的内容时,我差点错过了答案:然后我键入:localhost/Alpha/管理员以转到管理员".这意味着您所有的URL设置都是错误的.

I almost missed the answer to this until I re-read your question and finally caught the bit in the last line: "and I type: localhost/Alpha/admin to go to admin". That means all your URL settings are wrong.

当前,您有:

MEDIA_URL = '/media/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

这些应该是:

MEDIA_URL = '/Alpha/media/'
STATIC_URL = '/Alpha/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

此外,在 STATICFILES_DIRS 中不需要"static/".因此,请删除该设置.

Additionally, you don't need "static/" in STATICFILES_DIRS. So remove that setting.

这篇关于Django静态文件未使用默认设置加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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