| 94 | == Idea 5: Class plus decorator == |
| 95 | {{{ |
| 96 | #!python |
| 97 | from django.views.decorators.shortcuts import use_template |
| 98 | |
| 99 | class AClass(BaseClass): |
| 100 | #class level attributes here (e.g. for the menu generation - see below) |
| 101 | |
| 102 | @use_template('primes/index') |
| 103 | def prime_index(request): |
| 104 | return { |
| 105 | 'title': 'Page Title', |
| 106 | 'primes': [2, 3, 5, 7], |
| 107 | 'header': 'The first 4 primes' |
| 108 | } |
| 109 | }}} |
| 110 | |
| 111 | If i dynamically build a menu, etc. I would like to be able to define that at the class level so that I don't have to repeat myself in every method, or repeat myself decorating every method. I'm kind of new to python and am not familiar with all its capabilities so my example may not be the best. |
| 112 | |