我正在尝试设置django项目,我似乎遇到了我的urlconf问题。我不确定这笔交易是什么,下面的错误对我来说并不完全有用。我认为它实际上与模板渲染没有任何关系,因为我逐步执行了执行路径,直到render_to_response函数完成之前(这是urlconf似乎导致错误的地方)并且模板对象被解析正确。
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>
这是我的顶级urlconf:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'', include('pub.urls')),
)
并且pub.urls:
from django.conf.urls.defaults import *
import pub
urlpatterns = patterns('pub.views',
(r'^$', 'index')
)
和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
答案 0 :(得分:1)
确保每个.py文件在语法上都是正确的。运行python manage.py shell
,然后运行import
每个模块,确保加载时没有错误。由于语法错误是python中的运行时错误,因此错误有时会出现在奇数时间和奇数位置。
答案 1 :(得分:0)
这是另一个可能在将来派上用场的建议。
由于许多可能的原因,在Web界面中打印的堆栈跟踪并不总是最佳的。但是,您还可以将一个堆栈跟踪输出到控制台,这可能会为您提供网页上省略的信息。
最简单的方法是使用内置的网络服务器(即python manage.py runserver 0.0.0.0:8000
)运行django,并使用浏览器访问该页面。您应该看到堆栈跟踪与控制台上的Web服务器日志记录输出内联,这可能包含“不可打印”的错误内容。
答案 2 :(得分:0)
看起来问题是因为我的模板包含一个无法解析的{%url ...%}块,因此抛出了NoReverseMatch异常。来自django站点:请注意,如果您正在撤消的URL不存在,则会引发NoReverseMatch异常,这将导致您的站点显示错误页面。