django: 开发服务器下admin界面没有css
来源:互联网 发布:知乎怎么更新答案 编辑:程序博客网 时间:2024/06/06 05:36
为了省心,选择了bitnami的集合软件: bitnami-djangostack-1.5.5-1-windows-installer。
安装完成后,python, django, apache, postgresql, sqlite3全都有了,python版本是2.7.6的,django是1.4的 ,看起来很方便,但是是那么完美吗?
开始跟着The Django Book 学,到了启用admin界面时,总是给个黑白的,不是彩色的,漂亮的界面:
学习阶段,直接使用 manage.py runserver命令了。
看了很多百度的文章,包括django的官方文档,都是说只要:
- settings中的debug要为True
- settings中INSTALLED_APPS中要有 'django.contrib.staticfiles'
就可以了。
而STATIC_URL = '/static/' 这句,默认就有。
django说,开发服务器会自动解析静态文件。
折腾1天,试了各种参数,如STATIC_ROOT(证明这个只对用manage.py collectstatic 起作用),一度怀疑要使用 django-admin.py runserver来运行开发服务器。
其实在浏览器地址栏里打 http://127.0.0.1:8000/admin/后,点菜单,开发服务器是有错误提示的:
python2.x 默认编码是ascii。 这个开始真不懂。
觉着可能是开发服务器读取静态文件,而模块里按utf-8处理,出现字符串混乱,而导致css、js及image文件找不到。
就打算看看让python 2.x运行在utf-8下。
百度了个文章:
可以手动建一个sitecustomize.py强制python使用utf-8。
开始看的文章里面把utf-8写成utf8了,照着弄错了。
python的编码是utf8,自然不对,还是错误。
可以看这个博客,他这个是对的。
看到这文章晚了,把bitnami的集成包卸载了。
安装了Python 3.33和django 1.6.1,Python自带sqlite3,学习是足够了。
Python3默认就是utf-8了,大家都统一了,世界终于一片清凉:
运行正常的开发服务器:
实际,python 2.x如果运行在utf-8下也应该可以。
反正2.7.6的版本,语法与3.x的差不多了,更换版本没有
跨平台的东西,比微软的就是复杂,一个编码就让人头疼半天。
而且版本之间的一致性要特别加以小心。
这次没有好好看错误信息,也走了很多弯路。
学习的过程中,会有很小的拦路虎,要战胜它,一遇到困难就放弃,就总是浅尝辄止,而不能学会一门技能。
对于 File "D:\Python\Lib\mimetypes.py", line 249, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
This is a bug in mimetypes, triggered by bad data in the registry. (рєфшю/AMR is not at all a valid MIME media type.)
ctype is a registry key name returned by _winreg.EnumKey, which mimetypes is expecting to be a Unicode string, but it isn't. Unlike _winreg.QueryValueEx, EnumKey returns a byte string (direct from the ANSI version of the Windows API; _winreg in Python 2 doesn't use the Unicode interfaces even though it returns Unicode strings, so it'll never read non-ANSI characters correctly).
So the attempt to .encode it fails with a UnicodeDecodeError trying to get a Unicode string before encoding it back to ASCII!
These lines in mimetypes should simply be removed.
注释掉上面几行。
验证可以用。
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
This is a bug in mimetypes, triggered by bad data in the registry. (рєфшю/AMR is not at all a valid MIME media type.)
ctype is a registry key name returned by _winreg.EnumKey, which mimetypes is expecting to be a Unicode string, but it isn't. Unlike _winreg.QueryValueEx, EnumKey returns a byte string (direct from the ANSI version of the Windows API; _winreg in Python 2 doesn't use the Unicode interfaces even though it returns Unicode strings, so it'll never read non-ANSI characters correctly).
So the attempt to .encode it fails with a UnicodeDecodeError trying to get a Unicode string before encoding it back to ASCII!
try: ctype = ctype.encode(default_encoding) # omit in 3.x!except UnicodeEncodeError: pass
These lines in mimetypes should simply be removed.
注释掉上面几行。
验证可以用。
0 1
- django: 开发服务器下admin界面没有css
- Nginx下Django Admin界面Css、JS丢失问题解决方法
- Django admin界面丢失CSS解决办法
- Django优化admin界面
- django admin界面中文
- 自定义Django的admin界面
- django admin 界面标题更改
- pythonWeb -- Django开发- Admin
- python Django的admin 后端出现了白班,既没有css效果
- 解决Django Admin管理界面样式表(CSS Style)丢失问题
- 关于Django 中启动自带服务器进入后台admin没有样式的问题...
- 开发:Django(2)Admin
- Django开发博客-(4)Admin
- django admin 报错没有发现 table
- django--Admin界面管理 model:TemplateSyntaxError 解决办法
- django admin 界面支持中文用户名
- Django基础(3)admin管理界面
- Django 采用bootstrap-admin的界面部署
- WPF TextBox的SpellCheck功能
- 元素周期表顺口溜(转载)
- php+jquery插件imgAreaSelect图片裁剪保存
- 系统分析之二 需求获取的调查研究技术
- 【黑马程序员】Java基础加强14:JDK1.5枚举
- django: 开发服务器下admin界面没有css
- ASIHTTPRequest 详解
- 系统分析之三 使用用例建模系统需求
- 山水画
- 系统分析之四 数据建模和分析
- Jquery 实现 图片延迟加载
- JAVA数据源连接方式汇总
- 系统分析之五 过程建模
- 图 深度优先遍历 广度优先遍历 非递归遍历 图解算法过程