UnicodeDecodeError Class Based Views, urls
Question: I have this in a app url, I cannot figure out what is wrong. and the "encoding
Error" I am learning from 2 scoops of django.

The problem is this It is this because when I comment out it's use everything
works fine

    
    
    #!/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"
    ),
    )
    

This is my 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)
    


Answer: It appears that you have unicode code points in your template. By looking at
the hex you can see the raw bytes:

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

The part right after the r" is a ^ which appears to have been entered in
unicode. It shows as .. and the bytes are 0xcb 0x86. So your regex has unicode
but probably should only be ascii, so you should change this:

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

into this:

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

If you change all of those it probably fixes it.

