Skip to content Skip to sidebar Skip to footer

Django 1.8:xview Is Missing A Queryset. Define Xview.model, Xview.queryset,

I am getting error when go to the url: /result_list.html. But there is indeed queryset in the views.py, so what could be other reasons? Thanks in advance. The function is based on

Solution 1:

There are multiple issues with your code:

  1. You have an if self.request.method == 'POST': block in your get_queryset method. If that evaluates to False then you fall back to the parent get_queryset method, which is what triggers the error (because the parent method needs to be given either a model or a queryset, as indicated in the error). So if you try a simple GET request to result_list/ it will fail because the ListView doesn't have a queryset.

  2. You shouldn't be rendering templates from inside the get_queryset method. That method should return a queryset and nothing else. This will fail.

  3. Your ResultView really shouldn't be handling the POSTed form data in the first place. You should be handling that in your FormView and then redirecting the user to the appropriate result view by using the FormViews success_url parameter as explained in the documentation on form processing.

Post a Comment for "Django 1.8:xview Is Missing A Queryset. Define Xview.model, Xview.queryset,"