I'm making a weblog site in Django. I have a Blog model like this:
class Blog(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)
...
And I want the front pages of each blog to be at URLs like this: www.example.com/blog-slug/
However, I'm also using Flatpages and will want that to be able to match URLs like this: www.example.com/flat-page/
So urlpatterns like this won't work:
urlpatterns = patterns('',
(r'^(?P<blog_slug>[-\w]+)/$', 'weblog_index', {}),
...
(r'^', include('django.contrib.flatpages.urls')),
)
because all Flatpages URLs will get trapped by the first pattern. I guess I want the first pattern to only match valid slugs from the Blog model, but I'm not sure how to do that.