Hi Bruno,

Your solution is more elegant and more DRY than the approach I took.
This is what I ended up with:

# urls.py
(r'^election/results/(?P<slug_name>[-\w]+)/(?P<year>\d{4})/((?
P<filetype>(js|htm))\/)?$', 'race.views.racename_detail'),

# views.py
def get_filetype(filetype):
    if filetype:
        return filetype
    else:
        return "html"

def get_mimetype(filetype):
    if filetype == "js":
        return "text/x-javascript"
    #elif filetype == "xml":
    #    return "text/xml"
    else:
        return "text/html"


def racegroup_detail(request, slug, year, filetype=None):
    item = RaceGroup.objects.get(slug__exact=slug,
date_created__year=year)

    t = loader.get_template('race/racegroup_detail.%s' % (get_filetype
(filetype)) )
    c = RequestContext(request, {
        'item ': item,
    })
    return HttpResponse(t.render(c), mimetype=get_mimetype(filetype))




And in the templates I have files, each with the same filename -- one
for for the javascript (.js), one for the full-template html (.html),
and one for the stripped-down html (I use the .htm extension for
these). I haven't done this yet, but I will work out a way to use the
stripped-down template as an include on the html template, and if
possible the javascript template.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to