add --> viewpost/1/ <------------- like this in url for any post i.e. continue reading

 step1:in template inside for loop  send id to the post you want to display url

     {% for post in post %}
<div class="post">
<div class="posttitle">
<span></span>
<div class="title">{{post.title}} </div></div>
<div class="postbody">
<div class="postdscimg">
<div class="postimg"><img src="{{post.image.url }}"></div>
<div class="postdsc">{{post.description}}</div>
</div>
<div class="postcontent">{{post.content|slice:"0:100"}}.....<a href="viewpost/{{post.id}}"><span>continue reading</span></a> </div>
<div class="publisheddate">published on:{{post.date}}</div>
</div>



</div>
{% endfor %}

step 2: add URL in urls.py
               path('viewpost/<int:id>/',views.viewpost,name='viewpost'),

step 3: make function in views .py with two argument request and id: fetch id from post database and send it to render
           def viewpost(request,id):
    
    post=Post.objects.get(id=id)
    context={'post':post}


    return render(request,'viewpost.html',context)   
   

Comments