###前提・実現したいこと
Djangoでブログを構築しております。
PcとSpでtemplateを切り替えたいと思っておりまして、Pcは /blog/top.html
spは /blog/sp/top.html
のようにtemplateを用意しております。
しかし、view.pyでuseragentを区分することができず苦戦しております。
template_name
をPcは /blog/top.html
、spは /blog/sp/top.html
のようにするにはどうすればいいのでしょうか。ご指南いただけると幸いです。
###該当のソースコード
■view.py class TopView(generic.ListView): template_name = 'blog/top.html' #←ここをuseragentなどの手段で区分したいです。 context_object_name = 'latest_post_list' paginate_by = 10 def get_queryset(self): """return the last five published questions.""" queryset = BlogPost.objects.filter( status__exact=2 ).order_by('-created') return queryset
###試したこと
from django.http import HttpRequest print(HttpRequest.META)
をやってもAttributeError: type object 'HttpRequest' has no attribute 'META'
となり取得できないです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。