3👍
✅
Your url should have pk
arg instead of new_str
path('details/<int:pk>/', PostDetailView.as_view(), name="post_details"),
1👍
You need to rewrite get_object
view.py
class PostDetailView(DetailView):
model = Post
template_name = 'blogs/blog_details.html'
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
new_str = self.kwargs.get('new_str') or self.request.GET.get('new_str') or None
queryset = queryset.filter(pk=new_str)
obj = queryset.get()
return obj
- [Django]-The empty path didn't match any of these
- [Django]-Are pre-save signals handled before the clean method in Django?
- [Django]-Django-rest-framework return created object but with fewer fields
-1👍
view.py
class PostDetailView(DetailView):
model = Post
template_name = 'blogs/blog_details.html'
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
new_str = self.kwargs.get('new_str') or self.request.GET.get('new_str') or None
queryset = queryset.filter(pk=new_str)
obj = queryset.get()
return obj
see http://www.chenxm.cc/article/1143.html
- [Django]-InvalidParameterValueError – Source bundle is empty or exceeds maximum allowed size: 524288000
- [Django]-Django Temporary Images
- [Django]-Django subquery using QuerySet
- [Django]-How do I properly configure my app to use the Django phonenumber field module?
- [Django]-Django comments reverse relationship
Source:stackexchange.com