I’m having an html form which inserts data into one table called srv.
I’ve built the urls.py in such a way to capture every insertion:
for item in srv.objects.all():
linkSrv = item.loc.lower() + '/srv/' + item.subctg.lower() + '/' + item.title.lower()
urlpatterns += patterns('',
url(r'^' + linkSrv + '/$', 'beta.views.queryFromIndexDeep'),
)
After the one insertion is being made, e.g. loc=’loc’, subctg=’subctg’ and title=’title’
if i point my browser to 127.0.0.1:8000/loc/srv/subctg/title/ i get the http404 error (no matching url)
If I ‘force-save’ the urls.py (vim urls.py then :x! ) – after loc,subct,title were inserted – then I can successfully access 127.0.0.1:8000/loc/srv/subctg/title/
Anyone can shed some light? It looks like the urlpatterns need to be ‘updated’ each time a row is insterted in srv table.
You should just use something like this:
Using regular expressions to match your view is way easier, and recommended. In your view, the above would match a function defined like
beta.views.queryFromIndexDeep(request, loc, subctg, title), from where you can continue to work with these variables to extract the relevant data from your defined models.