TLDR; {% url %} タグが機能します。r'(?i)^...$' URL パスが機能します。彼らは一緒に働きませんか?
(url テンプレート タグを使用して) 逆 URL 解決を使用したいのですが、何らかの理由で、大文字と小文字を区別しない URL 正規表現 (つまり、"(?i)" で始まる正規表現) と互換性がないようです。これが機能することを明確にするには:
urls.py:
...
urlpatterns = patterns('',
url(r'^$', home, name='home'),
...
)
...
base_path.html
<a href="{% url home %}">Users</a>
しかし、これは NoReverseMatch エラーを引き起こします:
urls.py:
...
urlpatterns = patterns('',
url(r'(?i)^$', home, name='home'),
...
)
...
具体的には、次のようになります。
NoReverseMatch at /p/blah/users/
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://localhost:8000/p/blah/users/
Django Version: 1.4.3
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found.
Exception Location: .../local/lib/python2.7/site-packages/django/template/defaulttags.py in render, line 424
Python Executable: .../bin/python
Python Version: 2.7.3
A)これが起こる理由、および/またはB)URLテンプレートタグまたは大文字と小文字を区別しないURL正規表現の回避策はありますか?この動作を他の多くの URL パスで再現しました。"(?i)" プレフィックスを削除することですべて修正しました (ただし、大文字と小文字を区別しないようにする必要があります)。