Passing id in url to get object info

I'm like 3 days trying to find the solution to this problem. I have a dashboard with items, every single item is called board. The dashboard is populated with object (board) that i've stored in my local db. Data like the name of this board is shown in the html page called dashboard.

What i want to do is, when i click on the link named 'Scopri di più' , to be redirected in the board.html populated with the clicked item data.

At the time i'm only getting the error 'NoReverseMatch'.

What am i doing wrong?

dashboard.html

{% extends "base.html" %}
{% block content %}
    <h3>{{title}}</h3>

    <a href="/new_board/" class="text-dark">Aggiungi Board</a>
    <div class="row mt-5">
        {% for bn in user_board_list %}
            <div class="col ml-4">

                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title"> {{ bn.board_name}} </h5>
                        <p class="card-text">Breve descrizione della board</p>
                                <a href="{% url 'board_view' pk=board.id %}">Scopri di più</a>
                        </div>
                </div>
            </div>
        {% endfor %}
            </div>

{% endblock %}

views.py

class Board_dets_view(DetailView):
    template_name = "board.html"

    def board_view(request, pk):
        title="Board"
        #board = get_object_or_404(request,pk=pk)
        board = Board.objects.get(pk=pk)
        context = {'title': title, 'board': board}
        return render(request, 'board.html', context)

models.py

class Board(models.Model):
    board_name = models.CharField(unique=True, max_length = 200, verbose_name='board_name',
                                  error_messages= {'unique': 'Nome della board già utilizzato. Per favore inseriscine un altro.'})
    creation_date = models.DateTimeField('data di creazione', auto_now_add=True)
    objects = models.Manager()
    id_user = models.ManyToManyField(User, related_name='user_board', verbose_name='id utente', through='Board_id_user')

    def __repr__(self):
        return self.name


urls.py

    path(r'board/<int:pk>', Board_dets_view.as_view() , name='board_view')



Read more here: https://stackoverflow.com/questions/64960443/passing-id-in-url-to-get-object-info

Content Attribution

This content was originally published by blackJarvis at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: