Chris Seymour
Chris Seymour

Reputation: 85873

Handle URLs for model entries only

Given a simple model:

class Blog(models.Model):
    blogname = = models.CharField(max_length=200,primary_key=True)

class BlogEntry(models.Model):
    blogname = models.ForeignKey('Blog')
    # more blog related fields 
    ...

and say the following blogs linux, python and other how would you handle the URLs to the respective blog pages pages. Currently I have set up a view to list all the blogs for the model Blog as the root page:

url(r'^$', 'blog.views.index')

The question is how to map the blog linux to /linux the way I am handling this currently is:

url(r'(?P<blog_name>.*)/','blog.views.blog_page')

but of course that means /.* is a valid URL and I only want /linux,/python and /other.

Upvotes: 0

Views: 56

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799300

Reject other values of blog_name with a Http404.

Upvotes: 4

Related Questions