这是观点:
def showProject(request, project_slug):
project = Project.objects.get(slug=project_slug)
tickets = Ticket.objects.filter(project=project)
payload = { 'project':project, 'tickets':tickets }
return render(request, 'project/project.html', payload)
这是错误:
回溯: get_response中的文件“C:\ Python27 \ lib \ site-packages \ django-1.3-py2.7.egg \ django \ core \ handlers \ base.py” 111. response = callback(request,* callback_args,** callback_kwargs) 在showProject中输入文件“C:\ project \ views.py” 13. project = Project.objects.get(slug = project_slug) 获取文件“C:\ Python27 \ lib \ site-packages \ django-1.3-py2.7.egg \ django \ db \ models \ manager.py” 132. return self.get_query_set()。get(* args,** kwargs) 获取文件“C:\ Python27 \ lib \ site-packages \ django-1.3-py2.7.egg \ django \ db \ models \ query.py” 349.%self.model._meta.object_name)
异常类型:/ project / ticket /中的DoesNotExist 异常值:项目匹配查询不存在。
对预期内容的更详细解释:我有一个侧栏,列出所有打开的“门票”。当我点击其中一张票时,它应该打开它。相反,当我尝试打开它时,我收到此错误。怎么了?
Per,request,这是模型类:
class Project(models.Model):
"""simple project for tracking purposes"""
name = models.CharField(max_length = 64)
slug = models.SlugField(max_length = 100, unique=True,blank=True, null=True)
description = models.CharField(max_length = 255)
owner = models.ForeignKey(User, related_name="+")
created_on = models.DateTimeField(auto_now_add = 1)
active = models.BooleanField(default=True)
parent = models.ForeignKey("self", related_name="children", null=True, blank=True)
repository = models.ForeignKey("Repository", related_name="projects", null=True, blank=True)
book = models.ForeignKey(Book, related_name="+", null=True, blank=True)
acl = models.ManyToManyField(AclEntry)
def save (self):
if not self.slug:
self.slug = '-'.join(self.name.lower().split())
if not self.book:
book = Book(name=self.name, owner=self.owner)
book.save()
self.book = book
super(Project, self).save()
似乎我尝试做的每件事都要回到这个,我不明白为什么?我错过了什么?非常感谢!
答案 0 :(得分:2)
project = Project.objects.get(slug=project_slug)
引发异常(DoesNotExist),意味着Project表中没有项目,其中一个slug对应于 project_slug
中的值你的网址中的正则表达式可能有误,发送给showProject视图的链接可能是错误的,或者表格中可能没有与该slug相对应的项目