1

I know this question has been asked many times but none of the solutions seems to work for me. I just started using django and I'm having issues trying to get the CSS for the admin panel to show when I use runserver.

When I'm in: localhost:8000/admin/ none of the CSS shows up

<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/admin/css/dashboard.css" />

That is what is shown in the in the HTML of the admin page, which those URL's it links to ends up becoming http://localhost:8000/static/admin/css/base.css which doesn't link to anything.

In settings.py I have

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'codeapp',
    'django.contrib.admin',
    'django.contrib.admindocs',
)

STATIC_ROOT = '/Users/datboitom/Sites/Codebase/codebase/codeapp/static/'
STATIC_URL = '/static/'

I'm just not too sure what else to do. If can help me to fix this issue that would be great. I've ran python manage.py collectstatic and the static files are in /Users/datboitom/Sites/Codebase/codebase/codeapp/static/ folder. There just doesn't seem to be any link between these files and whats trying to be loaded. One is trying to load off the localhost url and not the path of where its located on the computer.

4

5 回答 5

2

以防万一有人再次遇到此错误。在 Debug=False 模式下,Django 将不再为您提供静态文件。您的生产服务器应该负责这一点。但是,如果您仍然想在 debug=false 中本地测试您的应用程序,您应该在不安全模式下运行 devserver:

manage.py runserver --insecure

取自这里:为什么 DEBUG=False 设置使我的 django 静态文件访问失败?

于 2014-12-28T18:24:00.070 回答
0

I had this problem just recently after changing dev machines.

It turned out that my new machine wasn't set to run django apps in debug mode locally, so adding

DEBUG = True

To my dev machine's settings.py sorted it.

于 2014-11-17T21:30:01.070 回答
0

配置错误

在 setting.py 中,您应该 'django.contrib.staticfiles'在 INSTALLED_APPS
中添加代码显示:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
     ......

好的,试试看。

于 2013-11-11T02:36:45.430 回答
0

我猜您的 settings.py 文件中缺少以下内容

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
于 2013-01-04T05:43:05.977 回答
0

你的服务器设置是什么?

根据文档,您不应该在STATIC_ROOT

留空STATIC_ROOT,然后将路径放入STATICFILES_DIRS.

希望这可以帮助

于 2012-12-17T06:14:20.127 回答