Django - % url facebook_xd_receiver % 的问题
Posted
技术标签:
【中文标题】Django - % url facebook_xd_receiver % 的问题【英文标题】:Django - problem with % url facebook_xd_receiver %Django - % url facebook_xd_receiver % 的问题 【发布时间】:2011-03-02 13:33:59 【问题描述】:我正在使用
% url facebook_xd_receiver %
在我的一个 html 文件中。当我使用命令运行我的项目时,这工作得很好
python manage.py runserver
但是同一个项目停止运行并在该行给我一个“TemplateSyntaxError”
% url facebook_xd_receiver %
谁能告诉我通过命令行运行的开发服务器和apache服务器之间可能有什么区别。
在配置 Apache 服务器时我有什么遗漏吗?还是 Django 的问题?
编辑:实际报告 -
Environment:
Request Method: GET
Request URL: http://helvetica/djangonyc/exampleapp/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'djangonyc.exampleapp',
'djangonyc.facebookconnect']
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'facebook.djangofb.FacebookMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'facebookconnect.middleware.FacebookConnectMiddleware')
Template error:
In template /home/swat/website-apps/djangonyc/facebookconnect/templates/facebook/js.html, error at line 2
Caught an exception while rendering: No module named app.models
1 : <script type="text/javascript">
2 : FB_RequireFeatures(["XFBML"], function() FB.Facebook.init(" facebook_api_key ", " % url facebook_xd_receiver % "));
3 :
4 : function facebookConnect(loginForm)
5 : FB.Connect.requireSession();
6 : FB.Facebook.get_sessionState().waitUntilReady(function()loginForm.submit(););
7 :
8 : function pushToFacebookFeed(data)
9 : if(data['success'])
10 : var template_data = data['template_data'];
11 : var template_bundle_id = data['template_bundle_id'];
12 : feedTheFacebook(template_data,template_bundle_id,function());
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/swat/website-apps/djangonyc/exampleapp/views.py" in index
19. context_instance=RequestContext(request)
File "/usr/lib/pymodules/python2.6/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in render_to_string
108. return t.render(context_instance)
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
178. return self.nodelist.render(context)
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/pymodules/python2.6/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/pymodules/python2.6/django/template/loader_tags.py" in render
97. return compiled_parent.render(context)
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
178. return self.nodelist.render(context)
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/pymodules/python2.6/django/template/debug.py" in render_node
71. result = node.render(context)
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
946. autoescape=context.autoescape))
File "/usr/lib/pymodules/python2.6/django/template/__init__.py" in render
779. bits.append(self.render_node(node, context))
File "/usr/lib/pymodules/python2.6/django/template/debug.py" in render_node
81. raise wrapped
Exception Type: TemplateSyntaxError at /djangonyc/exampleapp/
Exception Value: Caught an exception while rendering: No module named app.models
【问题讨论】:
没有看到实际的错误报告。 尤其是 url 问题通常给出“NoReverseMatch”而不是“TemplateSyntaxError”。 【参考方案1】:实际的错误信息是这样的:
Caught an exception while rendering: No module named app.models
因此,您尝试在代码中的某处导入app.models
,它要么不存在,要么不在您的pythonpath 中。在 url 反转期间发生这种情况的原因是,为了找到所有可能的 URL,Django 导入所有视图 - 显然其中一个有错误。
【讨论】:
以上是关于Django - % url facebook_xd_receiver % 的问题的主要内容,如果未能解决你的问题,请参考以下文章