views:

121

answers:

3

I'm trying to get a django project set up, and I seem to be having trouble with my urlconf. I'm not sure what the deal is, and the error below isn't entirely helpful to me. I don't think it really has anything to do with template rendering, actually, because I stepped through the execution path until just before the render_to_response function completes (which is where the urlconf seems to be causing an error) and the template objects are parsed correctly.

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2978, in _HandleRequest
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 411, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2244, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2162, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2058, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\Ben\Development\workspace\ringbot\src\main.py", line 52, in <module>
    main()
  File "C:\Users\Ben\Development\workspace\ringbot\src\main.py", line 49, in main
    util.run_wsgi_app(application)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 97, in run_wsgi_app
    run_bare_wsgi_app(add_wsgi_middleware(application))
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 115, in run_bare_wsgi_app
    result = application(env, _start_response)
  File "C:\Python25\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "C:\Python25\lib\site-packages\django\core\handlers\base.py", line 134, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "C:\Python25\lib\site-packages\django\core\handlers\base.py", line 154, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Python25\lib\site-packages\django\views\debug.py", line 40, in technical_500_response
    html = reporter.get_traceback_html()
  File "C:\Python25\lib\site-packages\django\views\debug.py", line 114, in get_traceback_html
    return t.render(c)
  File "C:\Python25\lib\site-packages\django\template\__init__.py", line 178, in render
    return self.nodelist.render(context)
  File "C:\Python25\lib\site-packages\django\template\__init__.py", line 779, in render
    bits.append(self.render_node(node, context))
  File "C:\Python25\lib\site-packages\django\template\debug.py", line 81, in render_node
    raise wrapped
TemplateSyntaxError: <unprintable TemplateSyntaxError object>

Here is my top-level urlconf:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
   (r'', include('pub.urls')),
)

And pub.urls:

from django.conf.urls.defaults import *
import pub

urlpatterns = patterns('pub.views',
    (r'^$', 'index')
)

and pub.views.index:

# Create your views here.
from django.shortcuts import render_to_response
from django.http import HttpResponse
import openidgae

# this needs to be moved somewhere else, but for now it can live here
def index(request):
    lip = openidgae.get_current_person(request, HttpResponse())
    resp = render_to_response('pub/index.html', {'lip': lip}) # exception thrown here
    return resp
+1  A: 

Make sure each of your .py files is syntactically correct. Run python manage.py shell and then import each of your modules and make sure it loads with no errors. Since syntax errors are runtime errors in python, mistakes sometimes show up at odd times and in odd places.

tylerl
good suggestion, but in this case, I am able to import both my top-level module as well as the 'pub' module.
Ben Collins
A: 

Here's another suggestion which could come in handy in the future.

The stack trace printed in the web interface isn't always optimal for a number of possible reasons. However, you can also get a stack trace out to the console which might give you information that was omitted on the web page.

The easiest way to do that is to run django using the built-in webserver (i.e. python manage.py runserver 0.0.0.0:8000), and visit THAT page with your browser. You should see a stack trace appear inline with the web server logging output on the console, which may include otherwise "unprintable" error content.

tylerl
A: 

looks like the problem is because of a NoReverseMatch exception being thrown because my templates contain a {% url ... %} block that doesn't resolve. From the django site: Note that if the URL you're reversing doesn't exist, you'll get an NoReverseMatch exception raised, which will cause your site to display an error page.

Ben Collins