我在我的Django項目中使用Django註冊電子郵件。在那裏的文件(Django-Registration-Email),我被指示添加REGISTRATION_EMAIL_REGISTER_SUCCESS_URL在settings.py。然而,這是造成錯誤類型:Django註冊'str'對象不可調用
'str' object is not callable
在settings.py,我設置了重定向URL這樣:
REGISTRATION_EMAIL_REGISTER_SUCCESS_URL = '/accounts/register/complete/'
而且該URL複製這樣:
url(
r'^accounts/register/$',
RegistrationView.as_view(
template_name='registration/registration_form.html',
form_class=CustomEmailRegistrationForm,
get_success_url=getattr(
settings,'REGISTRATION_EMAIL_REGISTER_SUCCESS_URL',
lambda request, user:'/'),
),
name='registration_register',
),
調試信息告訴我,第一個錯誤來自/local/lib/python2.7/site-packages/registration/views.py in form_valid
指示的錯誤行是
success_url = self.get_success_url(request, new_user)
整個塊
def form_valid(self, request, form):
new_user = self.register(request, **form.cleaned_data)
success_url = self.get_success_url(request, new_user)
# success_url may be a simple string, or a tuple providing the
# full argument set for redirect(). Attempting to unpack it
# tells us which one it is.
try:
to, args, kwargs = success_url
return redirect(to, *args, **kwargs)
except ValueError:
return redirect(success_url)
回溯是:
Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/registration/views.py" in dispatch
79. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/registration/views.py" in post
35. return self.form_valid(request, form)
File "/Library/Python/2.7/site-packages/registration/views.py" in form_valid
83. success_url = self.get_success_url(request, new_user)
Exception Type: TypeError at /accounts/register/
Exception Value: 'str' object is not callable
誰能幫我解決這個問題?非常感謝!我被這個問題困住了一整天!
你可以發佈完整的Traceback嗎? – shaktimaan 2014-09-03 01:27:49
它可能與此相關嗎? http://stackoverflow.com/questions/10809240/typeerror-str-object-is-not-callable-django-python?rq=1 – faboolous 2014-09-03 01:41:35
我已經添加了回溯以及重定向url的設置。 – 2014-09-03 02:48:07