我最近开始从事同一个项目,我注意到一些我无法解决的奇怪问题。运行 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; 不能正常工作。我已经设置了边界