/__init __()处的TypeError恰好接受1个参数(给定2个) [英] TypeError at / __init__() takes exactly 1 argument (2 given)

查看:43
本文介绍了/__init __()处的TypeError恰好接受1个参数(给定2个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑为什么会收到此错误.我不知道这个额外的论点从何而来.

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)

由于这是一个全新的项目,所以我有些失落.我以为可能是我两次将网址指向同一个位置(一次在我的主url conf中,一次在应用程序本身中),但是一旦删除一个,似乎并没有解决.

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)

这是主要的urls.py:

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.

感谢帮助noobie.

Thanks for helping a noobie.

推荐答案

Home是基于类的视图.对于这些,您需要在URL模式中使用 as_view 方法:

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

请参见文档.

这篇关于/__init __()处的TypeError恰好接受1个参数(给定2个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆