django-'NoneType' object is not callable
I think this is your issue: You are using a FormView
but haven't defined a form class to use. Either set a form_class
attr on the class, or override the get_form_class
method:
class ReulstView(FormView):
context_object_name = 'result_list'
template_name = 'result_list.html'
model = Result
form_class = InputForm
Also, the form_valid
method will receive the form instance, you don't need to instantiate it manually:
def form_valid(self, form, **kwargs):
form = InputForm(self.request.POST) # <- remove this line
if form.is_valid():
...
Lets make another thread. :) The only way you can get "return outside function" error - you are trying to return something not from function. :) It could happen usually because of misstype or wrong indentation. Could you please provide the code where you get this error? I believe that there is something wrong with indentation there.
class ReulstView(FormView):
context_object_name = 'result_list'
template_name = 'result_list.html'
model = Result
if form.is_valid(): # <- it is not a function or method
# it is a class declaration
company = form.cleaned_data['company']
region = form.cleaned_data['region']
self.queryset=Result.objects.filter(region=region)
return render(request, 'result_list.html', {'form': form})
def get_context_data(self, **kwargs): #<- and this is a method
#... all your following code
I'm not familiar with Django FormViews, but looks like correct code could be like this:
class ResultView(FormView):
context_object_name = 'result_list'
template_name = 'result_list.html'
model = Result
def form_valid(self, form):
company = form.cleaned_data['company']
region = form.cleaned_data['region']
self.queryset=Result.objects.filter(region=region)
return render(request, 'result_list.html', {'form': form})