字典更新序列元素0的长度为6;需要2

2024-04-26 22:10:23 发布

您现在位置:Python中文网/ 问答频道 /正文

from django.shortcuts import HttpResponse, render
from .validate import create_validate_code
from io import BytesIO
from PIL import Image
from .forms import ContactForm

def test(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)

        if form.is_valid():
            your_name = form.cleaned_data['your_name']
            your_email = form.cleaned_data['your_email']
            your_country = form.cleaned_data['your_country']
            your_Product = form.cleaned_data['your_Product']
            your_comment = form.cleaned_data['your_comment']
            code = form.cleaned_data['code']

            if code == request.session['validate']:
                recipients = ['justman880221@live.com']
                content = your_comment + your_name + your_country

                if your_Product:
                    content.append(your_Product)

                from django.core.mail import send_mail
                send_mail(your_name, content, your_email, recipients)           
                return HttpResponseRedirect('/thanks/')

    else:
        form = ContactForm()

    return render(request, 'Samples/contact.html', {'form', form})

这一行引起的错误返回render(request,'Samples/联系人.html',{form',form})

我是新来的Django,能帮我找出哪个部分出了问题,以及如何解决这个问题?在

This is my form.py

^{pr2}$

This is html page

<form action="/Samples/test/" method="post">
    <p>
    {% csrf_token %}
    {{ form.as_p }}
    </p>
    <p class="form_p">
        <strong class="captcha_box">
            <span class="captcha_img"><img id="refresh_img" src="/Samples/validate/"/> </span> 
            <span onclick="myFunction()" title="Get a new challenge" class="captcha_reload ico" ></span>
        </strong>
    </p>
    <p class="form_p">
        <input class="btn" value="Seed Message" type="submit" />
    </p>
</form>

Tags: namefromimportformyourdataifrequest