我确实使用了django分页,但是网址存在问题,这是我的urls.py:
url(r'^/blog/$', blog_view.main, name='blog'),
url(r'^/blog/page/(?P<page_id>\d{0,9})$', blog.post, name='blog_page'),
我的views.py:
def post(request, page_id=None):
posts = Posts.objects.all()
pageid = page_id
return render(request, 'base.html', {'posts': posts, 'pageid': pageid,})
我的base.html使用bootstrap:
{% url 'blog_page' as blog_page %} # Blog page need follow patterns
<ul>
{% for post in posts %}
<li {% if request.path == htt://myblog.com/blog/page/5 %} class="active" {% endif %}>{{ post.title }}</li> # When I put blog_page django shows error. Help me how to put something to fix this condition.
{% endfor %}
</ul>
答案 0 :(得分:0)
正如documenation on HttpRequest objects所述,
HttpRequest.path
是
表示所请求页面的完整路径的字符串,不包括方案或域。
示例:&#34; / music / bands / the_beatles /&#34;
(强调我的)。
因此,在您的测试中,省略该计划(您,顺便说一句,错误地写为htt://
)和域名部分:
<li {% if request.path == /blog/page/5 %} class="active" {% endif %}>{{ post.title }}</li>