Alex, Thanks for the answer.
I tried doing something like the first thing you proposed (MEDIA_URL as a callable) but I had to tweak it a little bit because the template wasn't calling the callable, but rather printing 'function object .....'. What do you think of the solution I posted? Best, Martin On Jun 8, 11:29 am, Alex Robbins <alexander.j.robb...@gmail.com> wrote: > I haven't tested this, but it seems like you could do it one of two > ways: > > Define media root as a function in your settings.py. If you pass a > callable to the template, it will be called. > MEDIA_ROOTS = ['server1', 'server2', 'server3'] > def MEDIA_ROOT(): > from random import choice > return choice(MEDIA_ROOTS) > > OR > > Use a context processor to add MEDIA_ROOTS to the context and use the > random template tag. > > {{ MEDIA_ROOTS|random }} > > Steven's custom template tag works too. > > Alex > On Jun 8, 7:32 am, Martin Siniawski <msi...@gmail.com> wrote: > > > > > Steve, > > > Thanks for the answer. > > > If I understand correctly your idea and code, each template would have > > only one value for the MEDIA_URL (randomly chosen from the array), > > right? > > > What I was looking for was a way of distributing the value of the > > MEDIA_URL uniformly along the values of an array, in each template. So > > in a certain template the MEDIA_URL would have more than one value. > > Maybe if I set it as a callable (with the logic that choses the values > > inside it) that would work. > > > I cannot quite understand why there isn't anymore people running into > > this issue. > > > Best and thanks again for the answer, > > Martin > > > On Jun 7, 10:46 am, Steven L Smith <ssmit...@naz.edu> wrote: > > > > Hi Martin- > > > > I don't know what the "official" answer would be, but you could write > > > your own > > > context processor that had something like: > > > > from random import choice > > > MEDIA_URLS = 'static1.site.com', 'static2.site.com', 'static3.site.com' ] > > > def media(request): > > > return {'MEDIA_URL': choice(MEDIA_URLS)} > > > > Then, in settings.py, include your custom context processor instead of > > > the one > > > built-in to to Django. > > > > -Steve > > > > ==================================== > > > Steven L Smith, Web Developer > > > Department of Information Technology Services > > > Nazareth College of Rochester > > > 585-389-2085 | ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46 > > > ==================================== -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.