よく忘れるんでメモ
url の id とか
url(r'^foo/(?P<pk>\d+)/$', FooView.as_view(), name='foo'),
class FooView(TemplateView): template_name = 'index.html' def get_context_data(self, **kwargs): context = super(FooView, self).get_context_data(**kwargs) context['foo'] = Foo.objects.get(pk=self.kwargs.get('pk')) return context
- url が
foo/7/
の例self.kwargs.get('pk')
==7
url のパラメータ
search = request.GET.get('search')
- 例:
https://domain/method/?search=foobar
search
==foobar