For the default value to work as you expect, do this:

def view(request, year=None):
    if year is None:
        year = today.year()


Kwarg defaults are evaluated when the module is interpreted for the first time.

John


On Mar 26, 2014, at 1:57 PM, Anthony Hawkes <lifesillus...@gmail.com> wrote:

> Hi Guys,
> 
> I'm running into a problem with django(I guess this would also affect Python 
> in general) where if I create a view eg
> def view(year=today.year())
> The year is never re-evaluated until the server is reloaded/restarted
> 
> I'm trying to figure out how to make a callable method accessible as a 
> property if this is even possible to try and rectify this(not sure if this is 
> even the correct approach). I've had a look at some magic methods but can't 
> figure it out.
> 
> Basically I want to make eg
> 
> def year(something):
>     return 'blah'
> 
> Accessible using object.year as well as object.year()
> 
> Any pointers/ideas etc?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/e7adace8-ffc9-4f77-b970-e73bed5ae8e1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/FE30EAD3-E463-4379-B11C-970D86703AC3%40ipstreet.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to