返回

python-Django 'function' 对象没有属性 'objects'

发布时间:2022-06-22 19:38:06 269
# node.js

我的应用程序允许你喜欢图片,然后它会将你重定向到同一页面

当我尝试喜欢一张图片时,我会得到一个错误,我可以用shell提示符创建一个相似的对象,但为什么会出现这个错误呢?谢谢你帮助我

AttributeError at /like/3/
function' object has no attribute 'objects'Request Method: GET 
Request URL: http://127.0.0.1:8000/like/3/ 

Exception Value: 'function' object has no attribute 'objects' 
Traceback:
File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in get_response
111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\o\mysite\pet\views.py" in Like
195.     new_like, created = Like.objects.get_or_create(user=request.user, picture_id=picture_id)

这是我的views.py的一部分

def Like(request,picture_id):
    pid = picture_id
    new_like, created = Like.objects.get_or_create(user=request.user, picture_id=picture_id)
    p = Picture.objects.get(pk=pid)
    if created:
        HttpResponseRedirect(reverse('world:url_name'))
    else:
        HttpResponseRedirect(reverse('world:url_name'))

My URLconf:

     

url(Parts of my model: r'^like/(?P\d+)/$', 'pet.views.Like', name = 'Like' ), My boat.html

 {% if picture %}

 <ul>

    {% for pet in picture %}

    <li><b>description</b> = {{ pet.description}}<br/>

        {% if pet.image %}

 <li>

    <a href ="{% url world:Like pet.id %}">

        <img src= "{{ pet.image.url }}" style="cursor:pointer">

    </a>

 <li>

        {% endif %}

 {% endfor %}

 </ul>

 {% endif %}

 <a href="{% url world:PictureCreator %}">Add Pictures to your board</a><br/>


My models.py

class Picture(models.Model):
    user = models.ForeignKey(User)
    board = models.ForeignKey(Board,blank=False,null=False)
    image = models.FileField(upload_to="images/",blank=True)
    description = models.TextField()
    is_primary = models.BooleanField(default=False)
    def __unicode__(self):
        return self.description

class Like(models.Model):
    user = models.ForeignKey(User)
    picture = models.ForeignKey(Picture)
    created = models.DateTimeField(auto_now_add=True)    
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(2)
按点赞数排序
用户头像