Changes between Version 21 and Version 22 of NewformsHOWTO


Ignore:
Timestamp:
03/04/2008 10:03:07 AM (7 years ago)
Author:
Lllama <f.ingram.lists@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v21 v22  
    574574        return superclass.render_change_form(request, model, context, *args, **kwargs)
    575575}}}
     576
     577== Q: How can I pass extra context variables into my index page? ==
     578
     579You can't. At least not in the same way as above. The index page has a fairly
     580simple view, so you should just recreate it and add in the extra variables you need.
     581Here's an example
     582
     583
     584{{{
     585#!python
     586from django.contrib.admin.views.decorators import staff_member_required
     587from django.views.decorators.cache import never_cache
     588from django.utils.translation import ugettext
     589from django.shortcuts import render_to_response
     590from django import template
     591import subprocess
     592
     593def new_admin_index(request):
     594    # Here's our extra variable - output from the fortune package.
     595    fortune = subprocess.Popen("/usr/games/fortune -s", shell=True, stdout=subprocess.PIPE).communicate()[0]
     596
     597    return render_to_response('admin/index.html', {'fortune': fortune, 'title': ugettext('Site administration')}, context_instance=template.RequestContext(request))
     598new_admin_index = staff_member_required(never_cache(new_admin_index))
     599}}}
Back to Top