Hi,

I have a question regarding best-practice on django project structure,
I think I´ll best explain it with an example:

I have 2 views, first and second. I have the same function (which in
this case is a datetime-function) that is exactly the same in both
views.

views.py:
-----
from django.shortcuts import render_to_response
from datetime import datetime

def first( request ):

        format = '%Y-%m-%d %H:%M'
        current_date = datetime.now().strftime( format )

        return render_to_response('first.html', { 'current_date':
current_date })
-----

views2.py:
-----
from django.shortcuts import render_to_response
from datetime import datetime

def second( request ):

        format = '%Y-%m-%d %H:%M'
        current_date = datetime.now().strftime( format )

        return render_to_response('second.html', { 'current_date':
current_date })
-----

first.html:
-----
first: {{ current_date }}
-----

second.html:
-----
second: {{ current_date }}
-----


Is it possible for me to define this datetime-function just once and
without the need to include the 'current_date' variable to the
"render_to_response" function every time?
I would like some standard variables in my Django-project to be
available in all templates without the need to define the functions
for every view.
Is this what middleware are for?

Would be thankful for any tip/advice.
/Nianbig
--~--~---------~--~----~------------~-------~--~----~
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