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

问题描述:

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 = ['[email protected]'] 
       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}) 

引起这行返回错误渲染(请求, '样品/ contact.html',{ '形式',形式})字典更新序列元素#0的长度为6; 2需要

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

这是我form.py

from django import forms 


class ContactForm(forms.Form): 
    your_name = forms.CharField(label='Your Name', max_length=100) 
    your_email = forms.EmailField(label='Your Email') 
    your_country = forms.CharField(label='Your Country', max_length=100) 
    your_Product = forms.CharField(label='CEEONE Products', required=False, max_length=100) 
    your_comment = forms.CharField(label='Comment Or Specific Requests', widget=forms.Textarea, max_length=400) 
    code = forms.CharField(label='Type the text', max_length=100) 

这是html页面

<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> 

{'form', form}是一个集文字,而不是一个字典文字。

它应该是(, - >:

{'form': form} 

由于它是一个字典,它应该是不:,

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