Django URLConf does not match valid regex
I have a big problem with Django urlconf. I cannot get the regex to match in urls.py.
That's what I'm doing:
In my javascript i
var source = 'http://127.0.0.1:8000/quiltmaker/block'+i+'/shoefly'+i+'/';
which registers as
img.src http://127.0.0.1:8000/quiltmaker/block3/shoefly3/
my urlpatterns:
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^about/$', views.about, name='about'),
url(r'block(\d{1,3})/([a-z]{7})(\d{1,2})/$', views.block),
)
The regex works in the iPython interpreter:
js = 'block3/shoefly3/'
r = re.compile(r'block(\d{1,3})/([a-z]{7})(\d{1,2})/$')
r
Out[60]: re.compile(r'block(\d{1,3})/([a-z]{7})(\d{1,2})/$')
m = r.search(js)
m
Out[62]: <_sre.SRE_Match at 0x10f262ae0>
m.span()
Out[63]: (0, 16)
BUT Django never calls the view.
This works if urlpattern
url(r'block(\d{1,3})/shoefly(\d{1,2})/$', views.block)
Please, help. It drives me crazy as I already am.
+3
source to share
1 answer
Thanks to Peter Deglopper for pointing me in the right direction. Urlconf didn't send me to the view because the view was expecting two parameters and I was sending three. Adding another parameter to the view did the trick:
Before
def block(request, idx, blockno)
After
def block(request, idx, type, blockno)
+1
source to share