2
我收到以下錯誤:模板語法錯誤在Django
TemplateSyntaxError at /accounts/login/
Caught ImportError while rendering: No module named urls
由於這段代碼在模板:
<a href="{% url index %}">{% trans "Home" %}</a>
它試圖將我的django項目部署到amazon ec2實例後發生。我很困惑,爲什麼會發生這種情況。
這裏是完整的跟蹤:
TemplateSyntaxError at /accounts/login/
Caught ImportError while rendering: No module named urls
Request Method: GET
Request URL: http://ec2-67-202-59-6.compute-1.amazonaws.com:8000/accounts/login/
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
Caught ImportError while rendering: No module named urls
Exception Location: /opt/bitnami/apps/django/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /opt/bitnami/python/bin/.python.bin
Python Version: 2.6.5
Python Path:
['/opt/bitnami/projects/Project',
'/opt/bitnami/python/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/haystack-0.16-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/python_ptrace-0.6.4-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/jsonfield-0.9-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/django_pagination-1.0.7-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/django_picklefield-0.2.0-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/django_registration-0.7-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/django_jsonfield-0.8.5-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/South-0.7.3-py2.6.egg',
'/opt/bitnami/python/lib/python2.6/site-packages/django_haystack-1.2.6-py2.6.egg',
'/opt/bitnami/apps/django/lib/python2.6/site-packages',
'/opt/bitnami/projects/Project',
'/opt/bitnami/python/lib/python26.zip',
'/opt/bitnami/python/lib/python2.6',
'/opt/bitnami/python/lib/python2.6/plat-linux2',
'/opt/bitnami/python/lib/python2.6/lib-tk',
'/opt/bitnami/python/lib/python2.6/lib-old',
'/opt/bitnami/python/lib/python2.6/lib-dynload',
'/opt/bitnami/python/lib/python2.6/site-packages',
'/opt/bitnami/python/lib/python2.6/site-packages/PIL',
'/opt/bitnami/projects/Project/cookbook']
Server time: Tue, 4 Sep 2012 18:56:56 -0500
Template error
In template /opt/bitnami/projects/Project/templates/registration/base.html, error at line 56
Caught ImportError while rendering: No module named urls
46 </div><!--left_pane-container-->
47 </div><!--left_pane-->
48
49 {% block container %}
50 <div id="container">
51 <div id="container_header">
52 <div id="header-content-container">
53 <div id="container_header-items">
54 {% block header_items %}
55 {% endblock %}
56 <a href="{% url index %}">{% trans "Home" %}</a> |
57 {% if user.is_authenticated %}
58 {{ user.username }}
59 (<a href="{% url auth_logout %}">{% trans "Log out" %}</a> |
60 <a href="{% url auth_password_change %}">{% trans "Change password" %}</a>)
61 <form action="/search/" method="get">
62 <label for="id_q">Search:</label>
63 <input id="id_q" name="q" type="text">
64 <input type="submit" value="Submit">
65 </form>
66 {% else %}
這裏是完整的回溯:
Environment:
Request Method: GET
Request URL: http://ec2-67-202-59-6.compute-1.amazonaws.com:8000/accounts/login/
Django Version: 1.3
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.comments',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'pagination',
'cookbook',
'registration',
'ajax_validation',
'south',
'django.contrib.humanize',
'accounts',
'haystack',
'json']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'pagination.middleware.PaginationMiddleware')
Template error:
In template /opt/bitnami/projects/Project/templates/registration/base.html, error at line 56
Caught ImportError while rendering: No module named urls
46 : </div><!--left_pane-container-->
47 : </div><!--left_pane-->
48 :
49 : {% block container %}
50 : <div id="container">
51 : <div id="container_header">
52 : <div id="header-content-container">
53 : <div id="container_header-items">
54 : {% block header_items %}
55 : {% endblock %}
56 : <a href=" {% url index %} ">{% trans "Home" %}</a> |
57 : {% if user.is_authenticated %}
58 : {{ user.username }}
59 : (<a href="{% url auth_logout %}">{% trans "Log out" %}</a> |
60 : <a href="{% url auth_password_change %}">{% trans "Change password" %}</a>)
61 : <form action="/search/" method="get">
62 : <label for="id_q">Search:</label>
63 : <input id="id_q" name="q" type="text">
64 : <input type="submit" value="Submit">
65 : </form>
66 : {% else %}
Traceback:
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/auth/views.py" in login
69. context_instance=RequestContext(request, current_app=current_app))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/loader.py" in render_to_string
188. return t.render(context_instance)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in render
123. return self._render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/template/defaulttags.py" in render
437. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in reverse
391. *args, **kwargs)))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in reverse
312. possibilities = self.reverse_dict.getlist(lookup_view)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
229. self._populate()
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _populate
208. for name in pattern.reverse_dict:
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
229. self._populate()
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _populate
197. for pattern in reversed(self.url_patterns):
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: TemplateSyntaxError at /accounts/login/
Exception Value: Caught ImportError while rendering: No module named urls
我的猜測是 - 錯誤是其他地方..你可以做一個網站的搜索網址? – karthikr
我已經這麼做了,並且發現了一些事件。我究竟應該尋找什麼?謝謝karthikr –