At this endpoint, domain/dashboard/posts/. The titles for all posts are displayed, and I would like to know how to create hyperlinks on post titles in Django. When I click on the post title, the hyperlink on the post’s title diverts me to the detail page. Also, in which app will I make its URLs, views, model.py file, and post_detail.html file?
endpoint frontend
Files structure
dashboard/models.py
class Post(models.Model):
title = models.CharField(max_length=300)
blog_body = CKEditor5Field('blog body', config_name='extends')
auther = models.ForeignKey(User, on_delete=models.CASCADE , null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def \__str_\_(self):
return self.title
dashboard/views.py
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'posts/post_detail.html', {'post': post})
dashboard/urls.py
\# posts details
path('posts/<int:pk>/', views.post_detail, name='post_detail'),
main project urls.py
\# Dashboards
path('dashboard/', include('dashboards.urls')),
dashboard/templates/posts/post_list.html
{% extends 'base.html' %}
{% block content %}
<div class="row">
<!-- Left sidebar -->
<!-- load the sidebar here -->
{% include 'dashboard/sidebar.html' %}
<!-- Right side content -->
<div class="col-md-9">
{% if perms.blogs.add_category %}
<h3>Add New Category</h3>
<form action= "{% url 'add_category'%}" method = "POST" style="width: 500px;">
{% csrf_token %}
{{form | crispy}}
<button type="submit" class="btn btn-warning"> submit</button>
</form>
<br>
{% else %}
<h5 class="text-center text-danger"> You do not have permission to add category</h5>
{% endif %}
</div>
</div>
{% endblock %}
