【发布时间】:2021-04-04 06:17:48
【问题描述】:
问题是,我有一个迷你博客,里面有文章和用户简介(页面)。
我在站点/articlename
上显示文章
我想在站点/用户名
views.py(文章):
def post_detail(request, slug):
post = get_object_or_404(Post, slug=slug)
return render(request, 'post_detail.html', {'post': post })
views.py(个人资料用户):
class UserProfileView(DetailView):
template_name = 'users/profile/profile-user-view.html'
queryset = User.objects.all()
def get_object(self):
username = self.kwargs.get("username")
return get_object_or_404(User, username=username)
网址:
path('<str:username>', UserProfileView.as_view(), name='user_detail')
path('<slug:slug>', views.post_detail, name='post_detail')
现在我的用户个人资料在 site/username 打开,但文章没有在以下位置打开 网站/文章名称。
我怀疑 URL 中存在某种冲突(slug)。我怎样才能在没有其他目录的情况下打开站点/地址上的文章和帐户。如果有任何帮助,我将不胜感激。
【问题讨论】:
标签: django django-models django-rest-framework django-views django-templates