###django ListViewで複数のcontextを渡すには
タイトル通りです。
私は以下のようにしてTopicモデルのリストをtopics
としてtemplateに渡しています。
python
1class TopicListView(ListView): 2 model = Topic 3 context_object_name = 'topics' 4#略 5 6 def get_queryset(self): 7 queryset = Topic.objects.all() 8 return queryset
しかし諸事情により、templateに渡すものとしてstr値を付け足す必要がでてきました。イメージとしては以下のようです。
python
1class TopicListView(ListView): 2 model = Topic 3 context_object_name = 'topics' 4 context_object_name_2 = 'tuika' #? 5#略 6 7 def get_queryset(self): 8 queryset = Topic.objects.all() 9 tuika = 'tuika' #? 10 return queryset #?
検索すればでてくるだろうと思ったのですが、以外と情報がなくて詰まってしまいました。なので質問させていただきました。django ListViewで複数のcontextを渡すにはどうすればよいのでしょう?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/09 05:21 編集