如何在Django Admin中启用CSS样式?

时间:2011-07-22 15:33:55

标签: django django-admin

我已经设定:

ADMIN_MEDIA_PREFIX = 'C:/Python27/Lib/site-packages/django/contrib/admin/media/'

在管理员面板中,我有这样的CSS链接:

<link href="C:/Python27/Lib/site-packages/django/contrib/admin/media/css/base.css" type="text/css" rel="stylesheet">
<link href="C:/Python27/Lib/site-packages/django/contrib/admin/media/css/dashboard.css" type="text/css" rel="stylesheet">

我看这些文件 - 它们不是空的。我试图在模板中设置静态链接,但仍然没有。

2 个答案:

答案 0 :(得分:3)

ADMIN_MEDIA_PREFIX URL 前缀,而不是文件系统路径。您只需将路径放在域或本地主机之外,即:

ADMIN_MEDIA_PREFIX = '/media/'

将从'http:// localhost:8000 / media /'或'https://mydomain.com/media/'中提取媒体。

答案 1 :(得分:1)

问题可能在于寄存器(非拉丁符号),所以如果你没有Django Admin中的样式 - 你可能会有这样的错误,导致这种情况。

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 69, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 273, in __call__
response = self.get_response(request)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 59, in get_response
return self.serve(request)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 52, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line 39, in serve
return static.serve(request, path, document_root=document_root, **kwargs)
File "C:\Python27\lib\site-packages\django\views\static.py", line 54, in serve
mimetype, encoding = mimetypes.guess_type(fullpath)
File "C:\Python27\lib\mimetypes.py", line 294, in guess_type
init()
File "C:\Python27\lib\mimetypes.py", line 355, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 260, in read_windows_registry
for ctype in enum_types(mimedb):
File "C:\Python27\lib\mimetypes.py", line 250, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

<小时/> 如果您还没有Django管理中的样式,那么您必须查看无样式html页面中标记中给出的信息。也许这是像这样的编码问题。

有简单的解决方案。运行 regedit 并在XP中观看:

[HKEY_CLASSES_ROOT\CLSID\{4063BE15-3B08-470D-A0D5-B37161CFFD69}\EnableFullPage\MIME]

以及7个这样的键:

HKEY_CLASSES_ROOT\MIME\Database\Content Type 

必须有无效的符号(所有必须是英文),所以你需要重命名一些条目,一切都会正常工作。但是,实际上,将端代码和样式问题连接在一起需要很长时间。我希望这会节省你的时间。