I decided to set up dynamic URL creation in Django based on the names stored in the database objects. All of these pages should be handled by the same view, but I would like the database object to be passed to the view as a parameter when it is called. Is it possible?
Here is the code I have:
places = models.Place.objects.all()
for place in places:
name = place.name.lower()
urlpatterns += patterns('',
url(r'^'+name +'/$', 'misc.views.home', name='places.'+name)
)
Is it possible to pass additional information to the view without adding additional parameters to the URL? Since the URLs are from the root directory, and I still need 404 pages to display other values, I can't just use the string parameter. Is there a solution to abandon attempts to add URLs to root, or is there another solution?
I assume that I could search by the name itself, since all URLs should be unique anyway. Is this the only option?
source
share