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

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'^

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.



Solution #1:

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

url(r'^

See the documentation.

Respondent: ApathyBear

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .


, 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.

Solution #1:

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


See the documentation.

Respondent: ApathyBear

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

, home.as_view(), name='home'),

See the documentation.

Respondent: ApathyBear
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

, 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.

Solution #1:

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


See the documentation.

Respondent: ApathyBear
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.