1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | def media_urls(request):
media_urls = URLCycle(url_list=settings.MEDIA_URLS)
return {'MEDIA_URL':media_urls}
class URLCycle(object):
def __init__(self,url_list):
self.urls = url_list
self.iter = 0
def __str__(self):
if self.iter == len(self.urls):
self.iter = 0
url = self.urls[self.iter]
self.iter += 1
return url
|
More like this
- Use MEDIA_URL in flatpages with SSL by gobble 2 years, 10 months ago
- Load static media from secure (SSL) static server (Context Processor) by ianreardon 3 years, 7 months ago
- media_url context variable by marchino 6 years, 1 month ago
- Use MEDIA_URL in 500 error page by bthomas 4 years, 6 months ago
- Use MEDIA_URL in flatpages by robhudson 5 years, 1 month ago
Comments
I don't understand why you'd want to use it twice then fall back to media_url. I get the concurrent download limit-- though your number is wrong: http://stevesouders.com/ua/
But my main question is-- suppose you have 10 media requests to do-- how does limiting the first cycle to 2 requests help? You'd just pile the other 6 on one domain, right? 3-4 per domain is better than 6 to one, in terms of concurrency and likely completion, right?
If you accept my argument, this becomes simpler.
#
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.
#
Just an update on the above - you'd probably want to hit each subdomain at least twice so:
#