Django: Hi everyone, After updating a post, how do i redirect success message to full details page TEMPORARILY. because for my code now, after i update, i can see the updated message but even after refreshing, the updated success message remains there. kindly advise thank you!
views.py
def edit_blog_view(request, slug):
context = {}
blog_post = get_object_or_404(BlogPost, slug=slug)
if request.POST:
form = UpdateBlogPostForm(request.POST or None, request.FILES or None, instance=blog_post)
if form.is_valid():
obj = form.save(commit=False)
obj.save()
return redirect('HomeFeed:detail', slug=slug)
form = UpdateBlogPostForm(
initial = {
"brief_description": blog_post.brief_description,
"image": blog_post.image,
"body": blog_post.body,
}
)
context['form'] = form
return render(request, 'HomeFeed/edit_blog.html', context)
def detail_blog_view(request, slug):
context = {}
blog_post = get_object_or_404(BlogPost, slug=slug)
context['success_message'] = "Updated"
context['blog_post'] = blog_post
return render(request, 'HomeFeed/detail_blog.html', context)
detail_blog.html
{% if success_message %}
<div class="alert alert-success" role="alert"><h3 style="text-align: center;">{{success_message}}</h3></div>
{% endif %}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…