Answer the question
In order to leave comments, you need to log in
Direct GET? How to do it?
I have a view that processes a ListView and a form, it uses GET and filters posts based on their tag and displays them on the same page. Here:
class AllView(AjaxListView):
context_object_name = 'smth'
template_name = 'blog/all_things.html'
page_template = 'blog/things.html'
def get_queryset(self):
form = TagForm(self.request.GET)
if form.is_valid():
self.tag_name = (form.cleaned_data['tag']).lower()
return self.send_results(self.tag_name)
else:
self.tag_name = "All"
return Fact.objects.all()
def get_context_data(self, **kwargs):
context = super(AllView, self).get_context_data(**kwargs)
if 'TagForm' not in context:
context['TagForm'] = TagForm()
context['tag'] = self.tag_name
return context
def send_results(self, tag):
return Fact.objects.filter(tags__slug=tag)
<a>Food</a>
url(r'^(?P<tag>[\w-]+)$', views.TagView, name='tag'),
def TagView(request, tag):
# change this someday...
return HttpResponseRedirect(reverse('blog:all') + '?tag={}'.format(tag))
Answer the question
In order to leave comments, you need to log in
Janga parses the get itself and creates a dictionary in the request
def asdf(request):
print request.GET
#urls
# url(r'^(?P<tag>[\w-]+)$', views.TagView, name='tag'),
url(r'^/$', views.TagView, name='tag'),
# views
your_get_params_here = self.request.GET
<form method=get>
<input type=hidden name=tag value=Food>
<input type=submit>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question