0

我的 Django 应用程序的管理员如下所示。

Django 管理员

显然,一些样式表已经丢失和/或损坏。

问题:

  1. 哪些样式表用于以默认方式呈现 Django 管理员?
  2. 我在哪里可以找到它们?

更新 1 (10.06.2013 00:18 MSK):执行manage.py collectstatic会产生以下输出,并且不会改变管理员的外观。

D:\dev\history-site>C:\Python25\python manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\bas
e.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\cha
ngelists.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\das
hboard.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\for
ms.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\ie.
css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\log
in.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\rtl
.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\css\wid
gets.css'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\cha
ngelist-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\cha
ngelist-bg_rtl.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\cho
oser-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\cho
oser_stacked-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\def
ault-bg-reverse.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\def
ault-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\del
eted-overlay.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n-no.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n-unknown.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n-yes.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_addlink.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_alert.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_calendar.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_changelink.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_clock.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_deletelink.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_error.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_searchbox.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\ico
n_success.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\inl
ine-delete-8bit.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\inl
ine-delete.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\inl
ine-restore-8bit.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\inl
ine-restore.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\inl
ine-splitter-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\nav
-bg-grabber.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\nav
-bg-reverse.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\nav
-bg-selected.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\nav
-bg.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\sel
ector-icons.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\sel
ector-search.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\sor
ting-icons.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
l-left.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
l-left_over.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
l-right.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
l-right_over.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
ltag-add.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
ltag-add_over.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
ltag-arrowright.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\too
ltag-arrowright_over.gif'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\gis
\move_vertex_off.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\img\gis
\move_vertex_on.png'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\acti
ons.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\acti
ons.min.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\cale
ndar.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\coll
apse.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\coll
apse.min.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\comp
ress.py'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\core
.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\getE
lementsBySelector.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\inli
nes.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\inli
nes.min.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\jque
ry.init.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\jque
ry.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\jque
ry.min.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\LICE
NSE-JQUERY.txt'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\prep
opulate.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\prep
opulate.min.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\Sele
ctBox.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\Sele
ctFilter2.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\time
parse.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\urli
fy.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\admi
n\DateTimeShortcuts.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\admi
n\ordering.js'
Copying 'C:\Python25\lib\site-packages\django\contrib\admin\static\admin\js\admi
n\RelatedObjectLookups.js'

72 static files copied.

D:\dev\history-site>

更新 2(10.06.2013 00:28):这是我的urls.py文件:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings

admin.autodiscover()


urlpatterns = patterns('',
    (r'^$', 'history_site.views.home'),
    (r'^opinion/(\d+)$', 'history_site.views.opinion_details'),
    (r'^admin/', include(admin.site.urls)),
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)

urlpatterns += staticfiles_urlpatterns()
4

2 回答 2

5

缺少管理员的静态文件。当你运行 Django 时,DEBUG = True它会自动提供静态文件。在生产中,您应该让您的网络服务器为它们服务(因为它们是静态的,并且使用 Django 动态地为它们服务是一种资源浪费)。

我建议检查这个 HOWTO。长话短说:

  1. 设置STATIC_URL为您喜欢的任何内容(默认即可/static/)。
  2. 设置STATIC_ROOT为一个目录,其中的文件将由您的网络服务器在STATIC_URL. (也就是说,当浏览器请求时yourdomain.com/static/foo,网络服务器应该去那里STATIC_ROOT取走foo
  3. ./manage.py collectstatic每次更改静态文件时执行。它将从您安装的应用程序 ( INSTALLED_APPS) 中收集所有文件并将它们复制到STATIC_ROOT.

在 Django admin 的情况下,它的静态文件也将被收集collectstatic(因为admin它只是一个普通的应用程序,它在你的INSTALLED_APPS.

于 2013-06-08T22:54:46.897 回答
0

尝试将 staticfiles 应用程序添加到您的settings.py

INSTALLED_APPS = (
  # ...
  'django.contrib.staticfiles',
)
于 2013-06-09T01:37:31.500 回答