from datetime import datetime from django.shortcuts import render_to_response TIME_OPEN = (9, 0) # 9am and 0 minutes TIME_CLOSED = (12 + 8, 0) # 8pm and 0 minutes class HoursOfOperationMiddleware(object): def process_request(self, request): # Slice [3:5] of a timetuple is the hours and minutes if not TIME_OPEN <= datetime.now().timetuple()[3:5] < TIME_CLOSED: return render_to_response('hoursofoperation/closed.html')