Django class-based mobile view template
I'm configuring Django to use a different mobile template, but I'm not sure how to set it up for class based views. If I include it in a class like below it throws an error.
class EventList(ListView):
model = Event
paginate_by = 10
context_object_name = 'events'
category = None
area = None
starts = None
ends = None
slug_level = ""
if request.mobile:
template_name = "mobile/mobile.html"
...
I have features like def get_queryset(self):
where to put it so that it uses a different mobile template since the request is not in a class based view
I use minidetector
in a function like this:
@detect_mobile
def home(request, template_name='pages/home.html'):
....
if request.mobile:
return render_to_response('mobile/mobile.html', context)
+3
source to share
1 answer
Mobile and desktop computers usually use the same HTTP methods, so CBV is not where you diverge between these clients.
Instead, you should look at client properties such as the user agent header and set the template name accordingly.
I think the next page gives a great introduction:
+1
source to share