0
我已經認真地收腰了幾天試圖弄清楚這些,並且已經絕對碰到了磚牆。我研究並閱讀了關於此問題的所有SO帖子,但最終可能會使用一些幫助。Django表單和'元組'對象沒有屬性'rsplit'錯誤
我想掛鉤一個簡單的聯繫表單,下面是我提交表單時拋出相同'tuple' object has no attribute 'rsplit' error
的代碼的最新版本。
我的Django的版本是1.9,並使用Python3.5
def contact(request):
title = 'Contact Us'
title_align_center = True
form = ContactForm(request.POST or None)
if form.is_valid():
form_email = form.cleaned_data.get('email')
form_message = form.cleaned_data.get('message')
form_full_name = form.cleaned_data.get('full_name')
subject = 'Site Contact Form'
from_email = settings.DEFAULT_FROM_EMAIL
recipient_list = [from_email, '[email protected]']
message = '%s: %s via %s' % (
form_full_name,
form_message,
form_email)
# some_html_message = ''' <h1>hello</h1> '''
email = EmailMessage(
subject,
message,
form_email,
recipient_list,
['[email protected]'],
reply_to=[from_email],
headers={'Reply-To': from_email},
)
email.send()
context = {
'form': form,
'title': title,
'title_align_center': title_align_center,
}
return render(request, 'pages/contact.html', context)
回溯
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8001/contact/
Django Version: 1.9
Python Version: 3.5.1
Installed Applications:
['accounts',
'comments',
'pages',
'posts',
'search',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_summernote']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/rooster/Documents/Development/boston_intercom/pages/views.py" in contact
80. email.send()
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/core/mail/message.py" in send
292. return self.get_connection(fail_silently).send_messages([self])
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/core/mail/message.py" in get_connection
250. self.connection = get_connection(fail_silently=fail_silently)
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/core/mail/__init__.py" in get_connection
36. klass = import_string(backend or settings.EMAIL_BACKEND)
File "/Users/rooster/Documents/Development/boston_intercom/venv/lib/python3.5/site-packages/django/utils/module_loading.py" in import_string
15. module_path, class_name = dotted_path.rsplit('.', 1)
Exception Type: AttributeError at /contact/
Exception Value: 'tuple' object has no attribute 'rsplit'
,請複製粘貼完整的追溯,這樣我可以糾正錯誤的原因。 – Rajesh
在settings.py文件中顯示默認電子郵件設置的結構。這些設置存在一些問題,這就是錯誤到來的原因。 –