我试图使用其他两个网址标签,然后pk和slug以外的细节视图。我有以下代码段:
views.py class UseCaseDetailView(DetailView): template_name = "useCaseExtract/useCaseDetail.html" model = UseCaseProfile context_object_name = 'usecaseprofile' '''I am trying to override the get_object method of DetailView to accept url tags project and usecasename instead of pk and slug''' def get_object(self): obj = get_object_or_404(UseCaseProfile, project=self.kwargs['project'], useCasename=self.kwargs['useCasename']) return obj urls.py ... path('/UseCaseDetail/', UseCaseDetailView.as_view(), name='UseCaseDetail') ... in my template file, I have the following link: /Trancel/UseCaseDetail/Nothing after I clicked the link, I got: ValueError: invalid literal for int() with base 10: 'Trancel' can you some please explain to me why I am getting this error?
您有能力将
Trance1
重命名为类似TranceOne
的名称吗?所以它不包含整数?你知道吗我认为您的问题是
1
当需要解析URL时..(因为它需要一个sting,但是它得到了带有1
的字符串)。你知道吗项目url标记是UseCaseProfile模型中的外键。为了查询UseCaseProfile,我修改了detailview中的get\u对象代码,如下所示。你知道吗
相关问题 更多 >
编程相关推荐