SyntaxError: unexpected character after line continuation character

175 views
Skip to first unread message

about2flip

unread,
Sep 14, 2009, 3:34:56 AM9/14/09
to Django users
I am learning from djangobook.com using the 2edition online ver. I am
doing my first view

from django.http import HttpResponse

def hello(request):
return HttpResponse("Hello world")
--------------------------------------------------------------
and this is my urls.py file:

from django.conf.urls.defaults import *
from mysite.views import hello

urlpatterns = patterns('',
('^hello/$', hello),

)

------------------------------------------------------------

sorry for the long error post but when I run this views.py on both my
desktop and laptop OS windows XP SP2 & 3, I get this error:

Traceback (most recent call last):

File "C:\Python26\lib\site-packages\django\core\servers
\basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)

File "C:\Python26\lib\site-packages\django\core\servers
\basehttp.py", line 651, in __call__
return self.application(environ, start_response)

File "C:\Python26\lib\site-packages\django\core\handlers\wsgi.py",
line 241, in __call__
response = self.get_response(request)

File "C:\Python26\lib\site-packages\django\core\handlers\base.py",
line 73, in get_response
response = middleware_method(request)

File "C:\Python26\lib\site-packages\django\middleware\common.py",
line 56, in process_request
if (not _is_valid_path(request.path_info) and

File "C:\Python26\lib\site-packages\django\middleware\common.py",
line 142, in _is_valid_path
urlresolvers.resolve(path)

File "C:\Python26\lib\site-packages\django\core\urlresolvers.py",
line 294, in resolve
return get_resolver(urlconf).resolve(path)

File "C:\Python26\lib\site-packages\django\core\urlresolvers.py",
line 216, in resolve
for pattern in self.url_patterns:

File "C:\Python26\lib\site-packages\django\core\urlresolvers.py",
line 245, in _get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)

File "C:\Python26\lib\site-packages\django\core\urlresolvers.py",
line 240, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)

File "C:\Python26\lib\site-packages\django\utils\importlib.py", line
35, in import_module
__import__(name)

File "C:\djproj\mysite\..\mysite\urls.py", line 2, in <module>
from mysite.views import hello

File "C:\djproj\mysite\..\mysite\views.py", line 1

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss
\fcharset0 Arial;}}

^
SyntaxError: unexpected character after line continuation character


I uninstalled and reinstalled my python and django. I am following
every detail of the tutorial. I don't understand why I keep getting
this error.

I appreciate your help.

Tim Chase

unread,
Sep 14, 2009, 4:23:23 AM9/14/09
to django...@googlegroups.com
> File "C:\djproj\mysite\..\mysite\views.py", line 1
>
> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss
> \fcharset0 Arial;}}
>
> ^
> SyntaxError: unexpected character after line continuation character


Looks like your views.py file was saved in RTF format instead of
plain-text. Re-save it in plain-text as .py and it should at
least take care of this error.

-tim


Ajit jena

unread,
Sep 14, 2009, 7:20:53 AM9/14/09
to django...@googlegroups.com
Hello,

 In url.py module

Try this

urlpatterns = patterns('',

(r'^$', '<project name>.<app name>.views.hello'),

)

 instead of

from mysite.views import hello

urlpatterns = patterns('',
       ('^hello/$', hello),
)

I hope this will fix ur issue.


Thanks,
 Ajit

about2flip

unread,
Sep 14, 2009, 10:14:23 AM9/14/09
to Django users
That worked, thank you very much!
Reply all
Reply to author
Forward
0 new messages