我在任何模板中使用'str' object has no attribute 'regex'
或任何其他参数时都会收到此错误{% url home %}
。
似乎传递给url
的任何参数都是作为字符串传递的,我不确定这是否是url获取其参数的方式。
有什么我很想念这里,我应该添加任何新的值设置为 TEMPLATE_CONTEXT_PROCESSORS 或 MIDDLEWARE_CLASSES 或任何其他。
我的 MIDDLEWARE_CLASSES 是
MIDDLEWARE_CLASSES = (
'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_CONTEXT_PROCESSORS 是
TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.csrf',
'django.core.context_processors.static',
"django.core.context_processors.media",
'django.core.context_processors.debug',
'django.core.context_processors.i18n',)
我的 myproject / urls.py 是
urlpatterns = patterns('',
#Action urls go here
url(r'^home/$', 'website.home.views.home', name='home'),
#Contentdeveloper urls go here
(r'^contentdeveloper/', include('website.contentdeveloper.urls')),
#Static urls go here
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT, 'show_indexes': True}),
)
我的 Views.py 是
def home(request):
return render_to_response('home/home.html', {}, context_instance=RequestContext(request))
我在 home / home.html 中的模板代码是
{% extends "base.html" %}
{% block content %}
{% url home %}
{% endblock %}
然后整个追溯
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\MirrarOrnamentsWebPortal\website\home\views.py" in home
19. return render_to_response('home/home.html', {}, context_instance=RequestContext(request))
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "C:\Python27\lib\site-packages\django\template\loader.py" in render_to_string
176. return t.render(context_instance)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
140. return self._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
823. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
74. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render
123. return compiled_parent._render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
823. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
74. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render
62. result = block.nodelist.render(context)
File "C:\Python27\lib\site-packages\django\template\base.py" in render
823. bit = self.render_node(node, context)
File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node
74. return node.render(context)
File "C:\Python27\lib\site-packages\django\template\defaulttags.py" in render
411. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in reverse
476. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
363. possibilities = self.reverse_dict.getlist(lookup_view)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in reverse_dict
276. self._populate()
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _populate
253. for name in pattern.reverse_dict:
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in reverse_dict
276. self._populate()
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _populate
243. p_pattern = pattern.regex.pattern
调试时发生了有线的事情,我在django\core\urlresolvers.py
函数中的_populate
处尝试了除了块,其中发生了异常并且一切都神奇地开始工作。
我在这里很困惑,这是一个django bug或者我可能做过的事情导致了这个问题。