how to create a dynamic link in django

The Answer is:

steps: in views:

def article_content_view(request,article_id):
content = Article.objects.get(id=article_id).content
context = {
    'content':content
}
return render(request,'article.html',context)

in urls:

path('article/<int:article_id>/', views.article_content_view,name= 'article_content'),

in template html file:

<a href="{% url 'article_content' article.article_id %}"</a>

and my problem solved by add an id for each post in view:

'article_id': article.pk

you can see my github repo for this project.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top