0

我最近开始从事同一个项目,我注意到一些我无法解决的奇怪问题。运行 Django 开发服务器并在浏览器中输入地址后,我在终端中得到以下输出:

[02/Oct/2012 00:38:08] "GET / HTTP/1.1" 200 482
[02/Oct/2012 00:38:09] "GET /static/style.css HTTP/1.1" 200 349
[02/Oct/2012 00:38:09] "GET / HTTP/1.1" 200 482
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 146, in get_response
    response = debug.technical_404_response(request, e)
  File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 432, in technical_404_response
    'reason': smart_str(exception, errors='replace'),
  File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 116, in smart_str
    return str(s)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 235, in __repr__
    return smart_str(u'<%s %s (%s:%s) %s>' % (self.__class__.__name__, self.urlconf_name, self.app_name, self.namespace, self.regex.pattern))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 52: ordinal not in range(128)

页面显示正确,服务器仍在工作,但我认为这很烦人。我也很好奇这是怎么回事。
因此,过了一会儿我发现,如果我在 urls.py 中注释掉第二个模式,则不再显示错误消息。我的 urls.py:

# -*- coding: utf-8 -*-

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'apps.articles.views.index', name='homepage'),
    url(r'', include('articles.urls', namespace='articles')),
    url(r'^admin/', include(admin.site.urls)),
)

和应用程序/用户/urls.py:

# -*- encoding: utf-8 -*-

from django.conf.urls import patterns, url

urlpatterns = patterns('articles.views',
    url(r'^articles/$', 'article_list', {'all': True}, name='article_list'),
)

我还注意到,我的 style.css 文件 isd/*position: absolute; 不能正常工作。我已经设置了边界

4

2 回答 2

1

您的应用程序名称是否包含非 ASCII 字符?

于 2012-10-01T23:15:33.703 回答
0

在 Linux 上,请确保您安装了language-pack-xx软件包,例如

sudo apt-get install language-pack-en

以便为所有受支持的包(包括 Python)提供英文翻译数据更新。


然后确保在从终端运行脚本之前设置您的区域设置,例如

$ locale -a | grep "^en_.\+UTF-8"
en_GB.UTF-8
en_US.UTF-8
$ export LC_ALL=en_GB.UTF-8
$ export LANG=en_GB.UTF-8

文档:man locale,,man setlocale

于 2017-09-26T12:02:10.653 回答