一个博客的标签。怎么取到?这个代码怎么总是提示好像哪拼写不对?

gq2018 发布于 2013/11/26 22:42
阅读 425
收藏 0
@login_required
def vipPost(request):
    if request.method == 'POST':
        form = ZbwxinfoPostForm(request.POST)
        if form.is_valid():
            newzbvipinfo = zbwxinfo(
                title = form.cleaned_data['title'],
                content = form.cleaned_data['content'],
                user = request.user,
                wxcategory = form.cleaned_data['wxcategory'],
                wxtags = form.cleaned_data['wxtags']
                )
            newzbvipinfo.save()
            return HttpResponseRedirect(reverse('wxarc', args=[newzbvipinfo.id]))
        else:
            return HttpResponse("你发布的信息有误,请返回修改再提交!")
    else:
        form = ZbwxinfoPostForm()
        variables = RequestContext(request, {'form':form})
        return render_to_response('wx/wx_post.html', variables)

这里面的:wxtags = form.cleaned_data['wxtags'] 是取的models里定义的标签,这样不对吗?总是提示:

TypeError at /wx/post/
'wxtags' is an invalid keyword argument for this functionRequest Method: POST 
Request URL: http://127.0.0.1:8000/wx/post/ 
Django Version: 1.5.1 
Exception Type: TypeError 
Exception Value: 'wxtags' is an invalid keyword argument for this function 
Exception Location: E:\Python27\lib\site-packages\django\db\models\base.py in __init__, line 415

 

难道是哪里拼写错了?

models.py:

class WXTag(models.Model):
    name = models.CharField(verbose_name=u'标签名字', max_length=12, unique=True)


    #wxart = models.ManyToManyField("zbwxinfo", through="wxTag", verbose_name="文学内容")
    #remark = models.CharField(u'标签信息', max_length=300, blank=True, null=True)

    def __unicode__(self):
        return self.name

    #def get_absolute_url(self):
     #   return '/topic/%d/' % self.id

    #def save(self):
     #   self.name = self.name.strip()
    #    super(WXTag, self).save()

    class Meta:
        verbose_name = '标签'
        verbose_name_plural='标签'
class zbwxinfo(models.Model):
    title = models.CharField(max_length=36)
    content = models.TextField()
    #infopic = models.FileField(upload_to='./pic/%Y/%m/%d/%H/', blank=True, null=True)
    wxcategory = models.ForeignKey(WXCategory, verbose_name=u'文学分类')
    user = models.ForeignKey(User)
    #ip = models.IPAddressField()
    datetimeinfo = models.DateTimeField(auto_now_add=True)
    #dq_time = models.DateTimeField(null=True, blank=True)
    clickcount = models.IntegerField(default=0)
    wxtags = models.ManyToManyField(WXTag, verbose_name='标签',blank=True,null=True)

wx_post.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>

<body>
Hello,欢迎来到zb.com!
<form method="post" action="">
{% csrf_token %}
  <table width="900px" border="1" class="style2" style="font-size:14px">
    <tr> 
      <td height="40" align="right">文学分类:</td>
      <td height="40">{{ form.wxcategory }} [<font color="red">必填选项</font>]</td>
    </tr>
    <tr> 
      <td height="40" align="right">文章标题:</td>
      <td height="40">{{ form.title }}×[<font color="red">必填选项</font>]</td>
    </tr>
    <tr> 
      <td align="right">信息内容:</td>
      <td>{{ form.content }}×[<font color="red">必填选项</font>]</td>
    </tr>
 
	    <tr> 
      <td align="right" width="160">文章标签:</td>
      <td>{{ form.wxtags }}-时间默认为30可修改天,如修改只可改里面的数字.</td>
    </tr>
    
    
  </table>
  
   <div class="form-actions">
   <input id="submit" type="submit" value="发 布 信 息" class="btn btn-primary"/>
   <input type="hidden" name="next" value="{{ next }}" > 
  </div><p></p></form>

</body>
</html>

 

forms.py:

class ZbwxinfoPostForm(forms.Form):
    wxcategory = forms.ModelChoiceField(label=u'文学分类', queryset=WXCategory.objects.all(), required=True)
    title = forms.CharField(label=u'信息标题', widget=forms.TextInput(attrs={'size':60, 'max_length':60}))
    content = forms.CharField(label=u'信息内容', widget=forms.Textarea(attrs={'size':10000, 'rows':15,'cols':80}))
    wxtags = forms.CharField(label=u'标签内容', widget=forms.TextInput(attrs={'size':10, 'max_length':10}))

 

 

一晚上有点头晕。哪有不对的?

这个标签不是这样写的?

加载中
返回顶部
顶部