Django - {%url facebook_xd_receiver%}的问题

时间:2010-06-11 08:22:23

标签: django url django-templates django-urls

我正在使用

{% url facebook_xd_receiver %} 

在我的一个HTML文件中。当我使用命令

运行我的项目时,这很好用
python manage.py runserver

但是同一个项目停止运行并在该行给我一个“TemplateSyntaxError” {% url facebook_xd_receiver %}

任何人都可以告诉我通过命令行运行的dev服务器与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

1 个答案:

答案 0 :(得分:2)

实际的错误信息是:

Caught an exception while rendering: No module named app.models

因此,在您的代码中,您尝试导入app.models,它不存在或不在您的python路径上。在url反转期间发生这种情况的原因是,为了找到所有可能的URL,Django导入所有视图 - 显然其中一个有错误。