简体   繁体   中英

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

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!')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM