项目匹配查询不存在错误?

编程入门 行业动态 更新时间:2024-10-15 12:31:04
本文介绍了项目匹配查询不存在错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是以下视图:

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)

这是错误:

追溯:文件C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\handlers \base.pyin get_response 111. response = callback(request,* callback_args,** callback_kwargs)文件C:\project\views.py在showProject 13. project = Project.objects.get(slug = project_slug)文件C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db $ get 132. return self.get_query_set()。get(* args,** kwargs)文件C:\在get 349.%self.model._meta中的Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\query.py。 object_name)

Traceback: File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "C:\project\views.py" in showProject 13. project = Project.objects.get(slug=project_slug) File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\manager.py" in get 132. return self.get_query_set().get(*args, **kwargs) File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\query.py" in get 349. % self.model._meta.object_name)

异常类型:DoesNotExist at / project / ticket / 异常值:项目匹配查询不存在。

Exception Type: DoesNotExist at /project/ticket/ Exception Value: Project matching query does not exist.

对于什么是预期的更详细的解释:我有一个侧栏列出所有打开的门票。当我点击其中一张票时,应该打开它。相反,当我尝试打开它,我收到这个错误。发生什么事?

A more detailed explanation of what is expected: I have a sidebar that lists all open "tickets." When I click on one of those tickets, it should open it. Instead when I try to open it, I am getting this error. What is happening?

每个请求,这里是模型类:

Per, request, here is the model class:

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()

似乎我试图做的一切都是回到这个,我不明白为什么?我失踪了什么非常感谢!

It seems that everything I try to do is going back to this, and I don't understand why? What am I missing? Thanks so much!

推荐答案

project = Project.objects.get(slug=project_slug)

正在引发异常(DoesNotExist),这意味着Project表中没有项目对应于 project_slug 中的值

is raising an exception (DoesNotExist), meaning that there is no project in the Project table with a slug corresponding to the value in project_slug

您的url中的正则表达式可能是错误的,发送给showProject视图的链接可能是错误的或有可能不是表中的一个项目,而是对应于那个slug

The regex in your urls might be wrong, the link sending you to showProject view might be wrong or there mightn't be a project in the table yet corresponding to that slug

更多推荐

项目匹配查询不存在错误?

本文发布于:2023-11-16 23:00:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607849.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   错误   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!