Задать вопрос

Тел: +7 965 3737 888

511

Просмотров

2

Ответов

Cycling MEDIA_URL context processor

This is a context processor that will allow you to cycle the values of your MEDIA_URL context variable. It will cycle through the urls defined in settings.MEDIA_URLS, so that you can distribute your media url's between multiple servers.

Вопрос полезен? Да0/Нет0
file_3463.py(418.0б)
None

Ответы (2):

Ответjohnboxall:20.12.2008
Ответ полезен? Да0/Нет0

Just an update on the above - you'd probably want to hit each subdomain at least twice so:

def ncycle(iterable n):
    while True:
        for i in range(n):
            for item in iterable:
                yield item

def cycle_media():
  if not hasattr(cycle_media, 'state'):
     cycle_media.state = ncycle(settings.MEDIA_URLS, 2)
  return cycle_media.state.next()

Ответgirasquid:12.12.2008
Ответ полезен? Да0/Нет0

Your code is much more compact - and nicer, too! Thanks for pointing it out to me - I didn't realize that there was something built-in to cycle through things for me.