2013-03-12 77 views
1

错误__init __()恰恰1参数(3中给出)

response = callback(request,*callback_args,**callback_kwargs) 
Exception Type: TypeError at /accounts/profile/ 
Exception Value: __init__() takes exactly 1 argument (3 given) 

这是我的代码

urls.py

from django.conf.urls import patterns, include, url 
from django.conf.urls.defaults import * 
from django.contrib.auth.views import password_reset, password_reset_done, password_change, password_change_done 
from django.views.generic import TemplateView 
from django.contrib import admin 

admin.autodiscover() 

urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), 
    (r'^accounts/', include('registration.urls')), 
    (r'^accounts/profile/$', TemplateView, {'template': 'registration/profile.html'}), 
    (r'^accounts/password_reset/$', password_reset, {'template_name': 'registration/password_reset.html'}), 
    (r'^accounts/password_reset_done/$', password_reset_done, {'template_name': 'registration/password_reset_done.html'}), 
    (r'^accounts/password_change/$', password_change, {'template_name': 'registration/password_change.html'}), 
    (r'^accounts/password_change_done/$', password_change_done, {'template_name': 'registration/password_change_done.html'}), 
) 

views.py

from django.conf import settings 
from django.http import HttpResponseRedirect 
from django.shortcuts import render_to_response 
from django.template import RequestContext 
from models import RegistrationProfile 
from forms import RegistrationForm 
from django.core.context_processors import csrf 

def activate(request, activation_key): 
    activation_key = activation_key.lower() # Normalize before trying anything with it. 
    account = RegistrationProfile.objects.activate_user(activation_key) 
    return render_to_response('registration/activate.html',{ 
     'account': account, 
     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS 
    }, context_instance=RequestContext(request)) 

c = {} c.update(csrf(request)) 

def register(request, success_url='/accounts/register/complete/'): 
    form = RegistrationForm() 
    if request.method == 'POST': 
     form = RegistrationForm(request.POST) 

     if form.is_valid(): 
      new_user=RegistrationProfile.objects.create_inactive_user(
       username=form.cleaned_data['username'], 
       password=form.cleaned_data['password1'], 
       email=form.cleaned_data['email'] 
       ) 
      return HttpResponseRedirect(success_url) 

    return render_to_response('registration/registration_form.html', { 
     'form': form 
    }, context_instance=RequestContext(request)) 
+0

任何人都可以帮助我解决这个错误。在此先感谢 – Mathi 2013-03-12 05:40:11

+2

如果您没有发布您的代码,我们如何帮助您? – catherine 2013-03-12 05:41:00

+0

您的视图代码为哪个档案? – catherine 2013-03-12 11:00:27

回答

17

您当前的错误是由将TemplateView传入您的url conf导致的。它应该是TemplateView.as_view()

urlpatterns = patterns('', 
    #... 
    (r'^accounts/profile/$', TemplateView.as_view(template= 'registration/profile.html')), 
    #... 
) 
+0

谢谢..忘了添加它,并且该错误消息没有帮助。 – Jeewes 2013-11-08 07:56:33

+0

邮政陷入困境,但这非常有用。当你传递类时,Django可以做一个有用的错误消息,但不能将'as_view()'版本传递给URL。 – Max 2015-02-13 15:57:32

+0

不确定哪个版本适合,但在django 1.6中,关键字应该是'template_name'而不是'template'。 – 2015-07-15 15:31:12

相关问题