finethen
finethen

Reputation: 433

Django: Transfer multiple data into next template

Good day,

I'm asking myself, if it's possible to transfer multiple informations as primary-keys inside my template!?

For example, when clicking on a link inside my table...

In this case im transfering the item-id:

<tbody>
    {% for item in dataset %}
        <tr>
            <td>
                <a href="{% url 'Examplepage' item.id %}">Item-Name</a>
            </td>
        </tr>
    {% endfor %}
</tobdy>

Now I want to transfer the id and - let's say - the name! Is something like this even possible?

<tbody>
    {% for item in dataset %}
        <tr>
            <td>
                <a href="{% url 'Examplepage' item.id item.name %}">Item-Name</a>
            </td>
        </tr>
    {% endfor %}
</tobdy>

And if it's possible, do I have to chage something inside my urls.py? Right now it's looking like this:

path('index/<str:pk>', views.example, name="Example"),

Thanks for all your help and a great day!

Upvotes: 0

Views: 42

Answers (1)

Dharmendrakumar Patel
Dharmendrakumar Patel

Reputation: 24

Your url should be

{% url 'Examplepage' id=item.id  name=item.name %}"

And your path should be

path('index/<str:id>/<str:name>/', views.example, name="Example"),

Upvotes: 1

Related Questions