hello i need a help

30 views
Skip to first unread message

Richard Dushime

unread,
Jul 5, 2021, 11:14:33 AM7/5/21
to django...@googlegroups.com
i am getting this error down  when trying to submit  my form data to email {{

ValueError at /contact

too many values to unpack (expected 4)
Request Method: POST
Request URL: http://localhost:8000/contact
Django Version: 3.2.4
Exception Type: ValueError
Exception Value:
too many values to unpack (expected 4)
Exception Location: C:\Users\RDM\Envs\env\lib\site-packages\django\core\mail\__init__.py, line 83, in <listcomp>
Python Executable: C:\Users\RDM\Envs\env\Scripts\python.exe
Python Version: 3.9.6
Python Path:
['C:\\Users\\RDM\\Desktop\\Web\\KVC\\KVC',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\python39.zip',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\DLLs',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39\\lib',
 'c:\\users\\rdm\\appdata\\local\\programs\\python\\python39',
 'C:\\Users\\RDM\\Envs\\env',
 'C:\\Users\\RDM\\Envs\\env\\lib\\site-packages']


Mon, 05 Jul 2021 15:04:30 +00
}}}


my settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '587'
EMAIL_HOST_USER = 'myac...@gmail.com'
EMAIL_HOST_PASSWORD = 'almxfemqayldytab'
EMAIL_USE_TLS = True

here is my views.py

def contact(request):
    if request.method == 'POST':
        f_name = request.POST['name']
        f_email = request.POST['email']
        f_subject = request.POST['subject']
        f_message = request.POST['message']

        # send mail function
        datatuple = (
            ('f_name','f_subject''f_message','f_email',
        ['myg...@gmail.com']),
            # second person
            ('f_name','f_subject''f_message','f_email',
        ['sec...@gmail.com'])
        )
        send_mass_mail(datatuple)
        
        if send_mass_mail(datatuple):
            messages.info(request,'thank you for contacting us')
            return redirect('contact')
        else:
            messages.info(request, 'try again sorry for inconveniency')
            return redirect('contact')
    else:
        messages.info(request, 'try again sorry for inconveniency')
        return redirect('contact')




here down urls.py

path("contact", views.contact, name="contact"),

then my form html


 <form action="{% url 'contact' %}" method="post" role="form" class="php-email-form" data-aos="fade-left">
              {% csrf_token %}
              <div class="form-row">
                <div class="col-md-6 form-group">
                  <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
                  <div class="validate"></div>
                </div>
                <div class="col-md-6 form-group">
                  <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
                  <div class="validate"></div>
                </div>
              </div>
              <div class="form-group">
                <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
                <div class="validate"></div>
              </div>
              <div class="form-group">
                <textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
                <div class="validate"></div>
              </div>
              <div class="mb-3">
                {% for fmessage in messages %}
                <div class="error-message sent-message">{{fmessage}}</div>
                {% endfor %}
              </div>
              <div class="text-center"><button type="submit" class="send">Send Message</button></div>
            </form>

          </div>









sum abiut

unread,
Jul 5, 2021, 3:05:32 PM7/5/21
to django...@googlegroups.com
The error message is very clear send_mass_mail only expect  4 values but you are passing in more than four.
You should only pass in four values.

datatuple = (
('f_subject', 'f_message','f_email',
# second person
('f_subject', 'f_message','f_email',
)


send_mass_mail(datatuple)


refer to the documentations


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJCm56LAbJHrbNFworRZsuD-hP5Gok6wH%2BvQw1NgQuwAJ9_S4w%40mail.gmail.com.

Richard Dushime

unread,
Jul 7, 2021, 2:05:08 AM7/7/21
to django...@googlegroups.com
thank you but i wanted to send all the 4 fields and the "to" arguments  how can i do it? .. its submission form data i tried to loook into the documentation everywhere they used 3 fields only 

Reply all
Reply to author
Forward
0 new messages