开发者

Caught AttributeError while rendering: 'str' object has no attribute '_meta'

def broadcast_display_and_form(request):

    if 开发者_开发知识库request.method == 'POST' :
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.cleaned_data['post']
            obj = form.save(commit=False)
            obj.person = request.user
            obj.post = post
            obj.save()

            readers = User.objects.all()
            for x in readers:
                read_obj = BroadcastReader(person = x)
                read_obj.post = obj 
                read_obj.save()
            return HttpResponseRedirect('/broadcast')
    else :
        form = PostForm()
    posts = BroadcastReader.objects.filter(person = request.user)
    return render_to_response('broadcast/index.html', { 'form' : form , 'posts' : posts ,} )

My template

{% extends "base.html" %} {% load comments %}

{% block content %}
<form action='.' method='POST'>

    {{ form.as_p }}
<p>
  <input type="submit" value ="send it" /></input>  
</p>    
</form>

{% get_comment_count for posts.post as comment_count %}
{% render_comment_list for posts.post %}

{% for x in posts %}

    <p>
       {{ x.post.person }} - {{ x.post.post }}
    </p>

{% endfor %}    


{% endblock %}


What is posts.post supposed to be? posts is a BroadcastReader QuerySet, and probably doesn't have such an attribute? I'm guessing the comment rendering tags are causing your error? Try removing them, or using posts.0 or similar to debug.

Which "post" do you actually want to display comments for? Your view logic is unclear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜