我使用Django将应用程序开发到博客 问题是当我打开出版物的链接时 例如,https:// //本地主机:8000 / article / 89 / 我想打开另一个小册子的链接,然后看一下 https://本地主机:8000 / article / 89 / article / 80 / 每当您单击链接时,都会发生相同的情况 请问有解决办法
view.py文章
def show_article(request, id):
post = get_object_or_404(articles, id=id)
add = comment_put.objects.all().filter(user_put = id).order_by('-id')
art = articles.objects.get(pk = id)
first = articles.objects.order_by('-id')[:1]
three = articles.objects.order_by('-id')[:4]
is_liked = False
if post.likes.filter(id=request.user.id).exists():
is_liked = True
context = {
'art': art,
'add': add,
'post': post,
'first': first,
'three': three,
'is_liked': is_liked,
'total_likes': post.total_likes(),
}
return render(request, 'home/article.html', context)
urls.py
url(r'article/(?P<id>\d+)/$', views.show_article, name='show_article'),
article.html
<!-- column -->
{% for sd in solo1 %}
<div class="col-lg-3 col-md-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{{sd.image.url}}" alt="Card image cap">
<div class="card-body">
<a class="" href="article/{{sd.id}}" style="color:#212529; text-decoration: none !important"><p class="card-text">{{sd.title}}</p></a>
</div>
</div>
</div>
<!--end column -->
{% endfor %}
答案 0 :(得分:0)
只需从斜杠开始链接即可! /
<a class="" href="/article/{{sd.id}}" style="color:#212529; text-decoration: none !important"><p class="card-text">{{sd.title}}</p></a>
当您的浏览器中有http://example.com/page/1/且链接类似于page / 2时,您将得到此结果http://example.com/page/1/page/2,而当链接为'/ page2'时,您将会得到http://example.com/page/2/