Sorry, I don't know anything about url namespaces, but this might help: If all you are doing is looking up an object and displaying it, I would use the built-in generic views[1]. Just provide a queryset and an object id or slug and slug field. Less code to debug and maintain. There is also a list display for your root url[2] inside the app.
[1] http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-list-detail-object-detail [2] http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-list-detail-object-list Hope that helps, Alex On Jul 27, 5:13 pm, chyea <ryanc...@unt.edu> wrote: > Hi all, > > I'm writing a very small, simple video game news media site. I'm > starting off small, with just Blurbs and Reviews. The Blurbs are > basically quick news articles. The Reviews are extensive articles > about a video game, ofcourse. > > So, since both Blurbs and Reviews are both types of articles, I just > created an abstract base class for a model - my Article model. And > then I created a Blurb and Review model. These models live in an > application named "articles". > > Now, with these two models the mission is simple - map some urls to > views that query the database for the model data and then render the > template. I really want my urls to look something like this... > > site.com/review/ > site.com/review/this-is-a-reviews-slug/ > > site.com/blurb/ > site.com/blurb/this-is-a-blurbs-slug/ > > Since the view for both of these urls would be identical, if i made it > generic by passing in the model type, I decided to whip up a base > urls.py that looked like the following:http://dpaste.com/71150/ > > That base urls.py file includes the same url patterns for the slug and > index views, which exist inside the actual "articles" application, and > the included urls.py file looks like this:http://dpaste.com/71151/ > > The two views that are being used here accept the relevant model as a > parameter and use it to query the database and simply pass the results > onto a generic template for displaying the data. This all sounds very > nice and elegant. I wasn't duplicating parts of my code and everything > I had written was very simple. The problem came though when in my > template I was wanting to display a permalink, or just simply use a > reverse lookup to get the link of the article currently being viewed. > > When using the {% url %} tag, the reverse lookup was for some odd > reason returning the "site.com/review/" pattern, which is the second > pattern, even if the article was a Blurb. I'm not sure why it'd choose > the second matching pattern instead of the first, but either way this > behavior is nothing something I was wanting to hack my way around. So, > I added in the namespaces and in my template tried to use them in the > reverse url lookup by doing the follow: {% url article:single > article.slug %}. This was still returning the "site.com/review/" > pattern match for some reason. > > So, I ask - is there something I'm doing wrong? Am I not properly > using namespaces? They sound to me like they should correct this > situation but don't appear to be working properly. Is there a better > way to organize this site layout? I could easily just create two apps > - one for blurbs and one for reviews but they'd both contain identical > code, with simple a different template tag line. I could also double > the number of views and url patterns in my articles app, and point > them all to their own custom templates. Both of these options are much > less elegant, though. > > Thanks for any advice in advance! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---