を。以下の関数を実行すると、エラーが発生します(画像が添付されています)。私が間違っていることは何ですか?send_emailは、(1つの)位置引数を取りますが、3を与えた - 私はそのためのDjangoのドキュメント以下の私のDjangoのPythonプロジェクトからテストメールを送信しようとしていますジャンゴPythonの
https://docs.djangoproject.com/en/2.0/topics/email/
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
def send_email(request):
subject = request.POST.get('subject', 'Test')
message = request.POST.get('message', 'Test Message')
from_email = request.POST.get('from_email', '[email protected]')
if subject and message and from_email:
try:
send_mail(subject, message, from_email, ['[email protected]'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('/contact/thanks/')
else:
# In reality we'd use a form class
# to get proper validation errors.
return HttpResponse('Make sure all fields are entered and valid.')
エラー:
トレースバック: 私は私の質問を明確にするだけでなくトレースバックを追加しています。期待しています
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
574. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
223. return view(request, *args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
62. return bound_func(*args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
58. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/contrib/admin/options.py" in changelist_view
1596. response = self.response_action(request, queryset=cl.get_queryset(request))
File "/home/jimtiaz/PycharmProjects/TestAoo/venv/lib/python3.6/site-packages/django/contrib/admin/options.py" in response_action
1330. response = func(self, request, queryset)
Exception Type: TypeError at /admin/home/something
Exception Value: send_email() takes 1 positional argument but 3 were given
?関数のシグネチャには1つの引数が必要であることは明らかですが、3つの引数を使用して関数のシグネチャを呼び出すことは明白ではありません。 –
@JaredGoguen、トレースを詳細に調べてみましょう。 – Junaid
@JaredGoguen、私は私の質問にトレースバックを追加しました。それはあなたを助けるだろうか? – Junaid