Redirect 如何重定向到django中的上一个分页页面
我在项目中使用ListView和详细视图。在列表视图中我使用Paginator和paginate_by=5呈现博客文章。用户可以通过单击打开详细视图的给定url来查看博客。有一个按钮可以返回,如果用户在列表视图中的第二、第三或任何其他分页页面中输入博客,如何返回我的列表视图中的上一分页页面。如何在DetailView中的back按钮中设置上一页的url。Django有没有合适的方法来解决这个问题 views.pyRedirect 如何重定向到django中的上一个分页页面,redirect,django-views,Redirect,Django Views,我在项目中使用ListView和详细视图。在列表视图中我使用Paginator和paginate_by=5呈现博客文章。用户可以通过单击打开详细视图的给定url来查看博客。有一个按钮可以返回,如果用户在列表视图中的第二、第三或任何其他分页页面中输入博客,如何返回我的列表视图中的上一分页页面。如何在DetailView中的back按钮中设置上一页的url。Django有没有合适的方法来解决这个问题 views.py class ArticleListView(ListView): 分页单位=5 模
class ArticleListView(ListView):
分页单位=5
模型=博客
模板名称='index.html'
排序=('-blog_published')
def获取上下文数据(自身,**kwargs):
context=super()。获取上下文数据(**kwargs)
上下文[“消息”]=“ListView
“获取上下文数据”方法被覆盖!”
返回上下文
类ArticleDetailView(详细视图):
模型=博客
模板名称='blog detail.html'
def获取上下文数据(自身,**kwargs):
context=super()。获取上下文数据(**kwargs)
context['extra_context']=“'get_context_data method'被覆盖!”
返回上下文
#url.py
app_name = 'Core'
urlpatterns = [
path('', ArticleListView.as_view(), name='home'),
path('detail/<int:pk>', ArticleDetailView.as_view(), name='blog-detail'),
path('create/', ArticleCreateView.as_view(), name='blog-create'),
path('update/<int:pk>/', ArticleUpdateView.as_view(), name='blog-update'),
path('delete/<int:pk>/', ArticleDeleteView.as_view(), name='blog-delete'),
]
app_name='Core'
URL模式=[
路径(“”,ArticleListView.as_view(),name='home'),
路径('detail/',articletailview.as_view(),name='blog-detail'),
路径('create/',ArticleCreateView.as_view(),name='blog-create'),
路径('update/',ArticleUpdateView.as_view(),name='blog-update'),
路径('delete/',ArticleDeleteView.as_view(),name='blog-delete'),
]
index.html
{{object_list}length}
{对象_列表%]中博客的%
-
{{forloop.counter}}
- {{blog.is|u updated}时间:“H:i:s”}-{{blog.blog|u author}默认值:“author”}
- {{blog.blog|body|safe|slice::200}}
{%empty%}
没有博客是可以避免的;)
{%endfor%}
{%if已分页%}
{%include“includes/paginator.html”%}
{%endif%}
blog-detail.html
{{object.blog_title|capfirst}
{{object.is|u updated|date:“SHORT_date_FORMAT”}-作者:{{object.blog|u author |默认值|如果没有:“author”}
当前时间为{%now“SHORT\u DATETIME\u FORMAT”%}
{{object.blog|body|safe}
{%if request.user.u经过身份验证%}
{%endif%}
谢谢你提前通知
app_name = 'Core'
urlpatterns = [
path('', ArticleListView.as_view(), name='home'),
path('detail/<int:pk>', ArticleDetailView.as_view(), name='blog-detail'),
path('create/', ArticleCreateView.as_view(), name='blog-create'),
path('update/<int:pk>/', ArticleUpdateView.as_view(), name='blog-update'),
path('delete/<int:pk>/', ArticleDeleteView.as_view(), name='blog-delete'),
]
<ul>
{{ object_list|length }}
{% for blog in object_list %}
<li class="{% cycle 'left' 'right' %}">
{{ forloop.counter }}
<ul>
<li><a href="{{ blog.get_absolute_url }} ">{{ blog.blog_title|capfirst }}</a></li>
<li> {{ blog.is_updated|time:"H:i:s" }} - {{ blog.blog_author|default:"Author" }}</li>
<br>
<li>{{ blog.blog_body|safe|slice:":200" }}...</li>
</ul>
</li>
<br>
<br>
{% empty %}
<p>No Blog is avoilable ;)</p>
{% endfor %}
</ul>
{% if is_paginated %}
{% include "includes/paginator.html" %}
{% endif %}
<p>{{ object.blog_title|capfirst }}</p>
<hr>
<p style="font-size: 70%">{{ object.is_updated|date:"SHORT_DATE_FORMAT" }} - <strong>by: {{ object.blog_author|default_if_none:"Author" }}</strong></p>
<p>Curront time is {% now "SHORT_DATETIME_FORMAT" %}</p>
<p>{{ object.blog_body|safe }}</p>
<a href="{% url 'Core:home' %}"><button type="button">back</button></a>
{% if request.user.is_authenticated %}
<a href="{% url 'Core:blog-update' object.pk %}"><button type="button">Update</button></a>
<a href="{% url 'Core:blog-delete' object.pk %}"><button type="button">Delete</button></a>
{% endif %}