我正在关注一本 Django 书籍(Django 1.0 Web Site Development)。我发现这本书虽然直截了当且易于阅读,但却遗漏了一些小细节。但是,我遇到的这个错误,我一直无法在线找到解决方案。谢谢你的帮助。
下面,我将 Tag 类添加到我的 models.py 文件中。
from django.db import models
from django.contrib.auth.models import User
class Link(models.Model):
url = models.URLField(unique=True)
class Bookmark(models.Model):
title = models.CharField(max_length=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
class Tag(models.Model):
name = models.CharField(max_length=64, unique=True)
bookmarks = models.ManyToManyField(Bookmark)
然后我尝试在 python shell 上运行以下代码:
from bookmarks.models.import *
bookmark = Bookmark.objects.get(id=1)
结果,我收到以下错误:
Traceback (most recent call last):
File "(console)", line 1, in (module)
File "c:\Python27\lib\site\-packages\django\db\models\manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 349, in get
% self.model._meta.object_name)
DoesNotExist: Bookmark matching query does not exist.