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()
.
- [Answered ]-Uploading multiple images with Django
- [Answered ]-How to integrate Django form with Ajax?
- [Answered ]-One to Many relationship of models in Django
- [Answered ]-Creating a new instance of a Custom User Model in Django
- [Answered ]-Function in Django Model class not taking self argument?
Source:stackexchange.com