Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError at / __init__() takes exactly 1 argument (2 given)

Tags:

python

django

I am a bit confused why I am getting this error. I do not know where it's getting this extra argument.

Environment:


Request Method: GET
Request URL: http://0.0.0.0:5000/

Django Version: 1.6.4
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'nirla.apps.blog')
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 "/Users/nir/nirla/venv/lib/python2.7/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 exactly 1 argument (2 given)

Since this is a brand new project, I am a bit lost. I thought it could be that I pointed my urls at the same place twice (once in my main url conf and once in the app itself), but that didn't seem to fix it once I removed one.

For reference, here is the view that I am running:

class home(View):
    template_name = "blog/home.html"

    def get(self, request, *args, **kwargs):

        return render(request, self.template_name)

Here is the main urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
from nirla.apps.blog.views import home


urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', home, name='home'),
)

As you can see, I have just started this project and everything is pretty bare. I can provide more info, but the project is bare.

Thanks for helping a noobie.

like image 465
ApathyBear Avatar asked Sep 15 '14 23:09

ApathyBear


1 Answers

Home is a class-based view. For those, you need to use the as_view method in your URL pattern:

url(r'^$', home.as_view(), name='home'),

See the documentation.

like image 93
Daniel Roseman Avatar answered Nov 18 '22 10:11

Daniel Roseman