2013-03-12 78 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

相關問題