Simple guestbook django: __init__() takes 1 positional argument but 2 were given

PythonDjango

Python Problem Overview


I'm new to Django and trying to make a simple guestbook application to get used to the environment. I get the following mistake, but I can't locate the error:

Exception Value: init() takes 1 positional argument but 2 were given.

from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin

class Bericht(models.Model):
	titel = models.CharField(max_length=50)
	auteur = models.ForeignKey(User, blank=True)
	email = models.EmailField(max_length=75)
	inhoud = models.TextField(max_length=10000, blank=True)
	datum = models.DateTimeField(auto_now_add=True)
	
	def __str__(self):
		return str(self.auteur) + " : " + str(self.titel)
		
	class Meta:
		verbose_name_plural = "berichten"
	
class BerichtAdmin(admin.ModelAdmin):
	list_display = ["auteur", "datum", "titel"]
	list_filter = ["datum", "auteur"]
	
admin.site.register(Bericht, BerichtAdmin)

The view

from django.shortcuts import render
from django.views.generic import ListView
from Gastenboek.models import *

class BerichtListView(ListView):
	model = Bericht.objects.all()
	template_name = 'template/bericht_lijst.html'
	paginate_by = 10
	context_object_name = "bericht_lijst"
# Create your views here.

urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'Niels.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
	(r"^(\d+)/$", 'Gastenboek.views.BerichtListView'),
	(r"", 'Gastenboek.views.BerichtListView'),
)

Traceback

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.6.1
Python Version: 3.3.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Gastenboek')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "C:\Python33\lib\site-packages\django\core\handlers\base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

Exception Type: TypeError at /
Exception Value: __init__() takes 1 positional argument but 2 were given

Python Solutions


Solution 1 - Python

In your urls.py:

You are missing .as_view()

change it to:

(r"^(\d+)/$", Gastenboek.views.BerichtListView.as_view()),
(r"", Gastenboek.views.BerichtListView.as_view()),

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2583429View Question on Stackoverflow
Solution 1 - PythonAlvaroView Answer on Stackoverflow