[Tutor] HttpResponse error

Vincent Jones jonesv at cox.net
Mon Oct 26 22:47:59 CET 2009


SyntaxError at /

("'return' outside function",
('c:\\Users\\Vincent\\Documents\\django_bookmarks\\..\\django_bookmarks\\boo
kmarks\\views.py', 15, None, 'return HttpResponse(output)\n'))

 

 

As you can tell I am very new to this I am realizing that it is very
important that indention and syntax is very important but i don't understand
why I am getting this error This is the the original script in the views.py

 

from django.http import HttpResponse

def main_page(request) :

   output = '''

  <html>

     <head><title>%s</title></head>

     <body>

        <h1>%s</h1><p>%s</p>

     </body>

  </html>

''' % (

      'Django Bookmarks',

      'Welcome to Django Bookmarks',

      'Where you can store and share bookmarks!'

)

return HttpResponse(output)

 

And this (below is the error)

 

Environment:

 

Request Method: GET

Request URL: http://127.0.0.1:8000/

Django Version: 1.1.1

Python Version: 2.6.1

Installed Applications:

['django.contrib.auth',

 'django.contrib.contenttypes',

 'django.contrib.sessions',

 'django.contrib.sites']

Installed Middleware:

('django.middleware.common.CommonMiddleware',

 'django.contrib.sessions.middleware.SessionMiddleware',

 'django.contrib.auth.middleware.AuthenticationMiddleware')

 

 

Traceback:

File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in
get_response

  83.                     request.path_info)

File "C:\Python26\Lib\site-packages\django\core\urlresolvers.py" in resolve

  216.             for pattern in self.url_patterns:

File "C:\Python26\Lib\site-packages\django\core\urlresolvers.py" in
_get_url_patterns

  245.         patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)

File "C:\Python26\Lib\site-packages\django\core\urlresolvers.py" in
_get_urlconf_module

  240.             self._urlconf_module = import_module(self.urlconf_name)

File "C:\Python26\Lib\site-packages\django\utils\importlib.py" in
import_module

  35.     __import__(name)

File
"C:\Users\Vincent\Documents\django_bookmarks\..\django_bookmarks\urls.py" in
<module>

  2. from bookmarks.views import *

 

Exception Type: SyntaxError at /

Exception Value: ("'return' outside function",
('c:\\Users\\Vincent\\Documents\\django_bookmarks\\..\\django_bookmarks\\boo
kmarks\\views.py', 15, None, 'return HttpResponse(output)\n'))

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091026/0db09ed9/attachment-0001.htm>


More information about the Tutor mailing list