テンプレートのいずれかで'str' object has no attribute 'regex'
ユーザーまたはその他の引数を使用すると、このエラーが発生します。{% url home %}
に渡される引数はすべてurl
string として渡されるようですが、それが 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のバグですか、それとも私が行った可能性のある何かが問題を引き起こしたのですか.