Ethan Pearce
Ethan Pearce

Reputation: 139

TypeError: get() takes 2 positional arguments but 3 were given

I am trying to get an input to appear on my page, and have been following Max Goodridge's walkthrough ep.45, but seem to have gotten myself stuck on this particular section. If anyone could assist this would be a massive help.

My urls.py:

 url(r'^bandlist/$', polls_views.bandlist, name='bandlist'),
 url(r'^bandlist/(\d+)/$', polls_views.BandView.as_view(), name='bandview'),

My views.py

def bandlist(request):
    query = Band.objects.order_by('bandname')
    args =  {'query': query}
    return render(request, 'bandlist.html', args)

class BandView(TemplateView):
    template_name = 'bandview.html'

    def get(self, request):
        form = BandForm()
        return render(request, self.template_name, {'form': form})

My forms.py

class BandForm(forms.Form):
    post = forms.CharField()  

And the template (band.html)

{% extends 'bbase.html' %}


{% block content %}
<h1>{{ band.bandname }}</h1>

<h5>Total Ratings: {{ band.totalrating }}</h5>
<h5>How many times have {{band.bandname}} been rated: {{ band.totalrated }}</h5>
<h5>Average rating (Out of 5): </h5>

<form method="post">
    {{ form.as_p }}
    <input type="submit" value="Score" />
</form>
{% endblock %}

After this, I will then be attempting to implement a rating and review system for each band. If anyone could give advice on that as well that would be very much appreciated.

EDIT: Here is the full traceback:

Internal Server Error: /bandlist/1/
Traceback (most recent call last):
  File "C:\Users\Ethan\Envs\OnNote\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
    response = get_response(request)
  File "C:\Users\Ethan\Envs\OnNote\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Ethan\Envs\OnNote\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Ethan\Envs\OnNote\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\Ethan\Envs\OnNote\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
TypeError: get() takes 2 positional arguments but 3 were given

Upvotes: 3

Views: 18387

Answers (1)

joe
joe

Reputation: 9464

Your get() method implementation is missing an argument.

First check with TemplateView ancestor class
https://docs.djangoproject.com/en/2.0/ref/class-based-views/base/#django.views.generic.base.TemplateView

Zoom in to see the exact get() method implementation https://docs.djangoproject.com/en/2.0/ref/class-based-views/base/#django.views.generic.base.View

  def get(self, request, *args, **kwargs):
        return HttpResponse('Hello, World!')

Upvotes: 4

Related Questions