views:

42

answers:

1

Django has excellent URLConf and URL reverse mapping/matching. I'm looking for a tip/trick to add arbitrary extensions to URLs generated by Django. Sometimes it's nice to see extensions that suggest your brand.

+1  A: 

OK, let's assume I want to publish some documents which are available in HTML, PDF, DOC, etc formats. The pattern in urlconf would look like this:

(r"^/docs/(?P<doc_slug>[\w-]+).(?P<ext>\w+)$", myapp.views.view_doc),

and the view:

def view_doc(request, doc_slug, ext):
    if ext == "html":
        #...
    elif ext == "pdf":
        #...
    else:
        return Http404("Document not available in this format")
Alex Lebedev
+1 Thanks, but not really. But you gave me an idea how to do this.
Viet