django - MEDIA_URL in class-based view -


i'm not able access media_url in class-based view.

my understanding has been create view, , context processor provide function-based view. i'm trying switch class-based, , no longer have access media_url.

do context processors not work class-based views? have add context manually now?

here processors:

template_context_processors = (     'django.contrib.auth.context_processors.auth',     'django.core.context_processors.media',     'django.core.context_processors.static',     'django.core.context_processors.request',     'django.contrib.messages.context_processors.messages',     'django.core.context_processors.request', ) 

my previous views looked like:

def my_view(request):     context = {         "foo": "bar"     }     return render(request, 'index.html', context) 

and able use {{media_url}}.

my class-based view looks like:

class myview(view):     def get(self, request):         context = {             "foo": "bar"         }         return render(request, 'index.html', context) 

and cannot access {{media_url}}

django 1.8 moved configuration of template_context_processors templates setting. beyond don't think shouldn't need access media_url in template. it's bad code smell me. should using url generated file storage api (i.e. {{ model.field.url }}).


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -