[Answered ]-Get page url and shorten link in Django Template

1👍

link_db=models.Arts() here you are referring to a new instace of the Art model; where you need to refer to the instance you have fetched, which is post:

from django.shortcuts import render, get_object_or_404

def artdetail(request,arts_id,slug):
      post = get_object_or_404(Post, id=arts_id,slug=slug)
      currentUrl = request.build_absolute_uri(post.get_short_id())
      return render(request,
                    'postdetail.html',
                    {'post':post,'Arts':Arts,'currentUrl':currentUrl})

1👍

link_db=models.Arts() results in link_db being a new object, which doesn’t have id assigned, maybe that’s why it doesn’t generate url.

I think instead link_db.get_short_id() you meant post.get_short_id().

Leave a comment