UnicodeDecodeError基于类的视图,网址

时间:2013-12-15 00:15:52

标签: python django

我在app url中有这个,我无法弄清楚出了什么问题。和“编码错误”我正在学习2勺django。

问题在于这是因为当我评论它的使用时一切正常

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ofertoj/urls.py

from django.conf.urls import patterns, url
from .views import *

urlpatterns = patterns("",
url(
regex=r"ˆ(?P<pk>\d+)/$",
view=OfertoDetailView.as_view(),
name="oferto_detail"
),

url(
regex=r"ˆ(?P<pk>\d+)/results/$",
view=OfertoResultsView.as_view(),
name="oferto_results"
),

url(
regex=r"ˆ(?P<pk>\d+)/listview/$",
view=OfertoListView.as_view(),
name="oferto_listview"
),

url(
regex=r"^(?P<pk>\d+)/createview/$",
view=OfertoCreateView.as_view(),
name="oferto_createview"
),


url(
regex=r"ˆ(?P<pk>\d+)/updateview/$",
view=OfertoUpdateView.as_view(),
name="oferto_updateview"
),
)

这是我的Stacktrace

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.5.4
Python Version: 2.7.4
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.comments',
 'django.contrib.sitemaps',
 'zinnia',
 'tagging',
 'mptt',
 'south',
 'registration',
 'blogs',
 'turtle',
 'ofertoj',
 'petoj')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template /home/talisman/projects/tempilo/templates/skeleton.html, error at line 20
   ascii
   10 :     <meta name="robots" content="follow, all" />


   11 :     <meta name="language" content="{{ LANGUAGE_CODE }}" />


   12 :     <meta name="viewport" content="width=device-width; initial-scale=1.0;" />


   13 :     <meta name="description" content="{% block meta-description %}Browse through a few featured Isla Vista Restaurants and we are here to take your order. 


   14 : Call night or day (805)689-6969 or order online{% endblock %}" />


   15 :     <meta name="keywords" content="{% block meta-keywords %}delivery,food,take-out {{ entry_tags|join:", "}}{% endblock %}" />


   16 :     <meta name="author" content="Brian Scott Carpenter" />


   17 :     {% block meta %}{% endblock %}


   18 :     <link rel="pingback" href="/xmlrpc/" />


   19 :     <link rel="shortcut icon" href="{{ STATIC_URL }}img/favicon.ico" />


   20 :     <link rel="home" href=" {% url 'home' %} " />


   21 :     <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}css/screen.css" />


   22 :     <link rel="stylesheet" type="text/css" media="print" href="{{ STATIC_URL }}css/print.css" />


   23 :     


   24 :     <link href='http://fonts.googleapis.com/css?family=Jolly+Lodger' rel='stylesheet' type='text/css'>  


   25 :      


   26 :     <!--[if lt IE 8]>


   27 :         <link rel="stylesheet" type="text/css" media="screen, projection" href="{{ STATIC_URL }}/css/ie.css" />


   28 :     <![endif]-->


   29 :     {% block link %}{% endblock %}


   30 :     {% block script %}{% endblock %}


    Traceback:
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/handlers/base.py" in get_response
      115.                         response = callback(request, *callback_args, **callback_kwargs)
    File "/home/talisman/projects/tempilo/tempilo/views.py" in home
      19.         return render_to_response(('index.html'),context_instance=RequestContext(request))
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/shortcuts/__init__.py" in render_to_response
      29.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/loader.py" in render_to_string
      177.         return t.render(context_instance)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in render
      140.             return self._render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in _render
      134.         return self.nodelist.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in render
      830.                 bit = self.render_node(node, context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/loader_tags.py" in render
      124.         return compiled_parent._render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in _render
      134.         return self.nodelist.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in render
      830.                 bit = self.render_node(node, context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/loader_tags.py" in render
      124.         return compiled_parent._render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in _render
      134.         return self.nodelist.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/base.py" in render
      830.                 bit = self.render_node(node, context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/template/defaulttags.py" in render
      413.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in reverse
      496.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in _reverse_with_prefix
      382.         possibilities = self.reverse_dict.getlist(lookup_view)
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in reverse_dict
      297.             self._populate()
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in _populate
      274.                     for name in pattern.reverse_dict:
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in reverse_dict
      297.             self._populate()
    File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/urlresolvers.py" in _populate
      265.             if p_pattern.startswith('^'):

    Exception Type: UnicodeDecodeError at /
    Exception Value: 'ascii' codec can't decode byte 0xcb in position 0: ordinal not in range(128)

1 个答案:

答案 0 :(得分:1)

您的模板中似乎有unicode代码点。通过查看十六进制,您可以看到原始字节:

280a 7265 6765 783d 7222 cb86 283f 503c  (.regex=r"..(?P<

r“之后的部分是一个似乎已经输入unicode的^。它显示为..并且字节是0xcb 0x86。所以你的正则表达式有unicode但可能只应该是ascii,所以你应该改变这样:

regex=r"ˆ(?P<pk>\d+)/$",

进入这个:

regex=r"^(?P<pk>/d+)/$",

如果你改变所有这些,它可能会修复它。