0
<table id="tabledata" class="tablecenter" style=" position: static; top:50%;">
<tr>
    <th>Username</th>
    <th>Email</th>
    <th>Role</th>
    <th>Action</th>
    <th>Remove User</th>
</tr>

{% for user in all %}
<tr>
    <td>{{user.first_name}} {{user.last_name}}</td> 
    <td>{{user.email}}</td>
    <td>{% if user.is_staff %} Admin {% else %} Practitioner {% endif %}</td>
    <td><a class="openButton" onclick="openForm()">Edit</a></td>
    <td><a href="{% url 'delete_user' pk=user.id %}" class="openButton">Delete</a></td>
</tr>
{% endfor %}
  

After running the server on local, the page gives syntax error.

enter image description here

2 Answers2

0

You are mixing url and path syntax. You use of path converters with path(…) [Django-doc], so:

# app_name/urls.py

from django.urls import path

urlpatterns = [
    # …,
    path('delete_user/<int:pk>/', views.delete_user, name='delete_user'),
    # …
]
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
0

I think you should use

According to docs https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#url

<table id="tabledata" class="tablecenter" style=" position: static; top:50%;">
<tr>
    <th>Username</th>
    <th>Email</th>
    <th>Role</th>
    <th>Action</th>
    <th>Remove User</th>
</tr>

{% for user in all %}
<tr>
    <td>{{user.first_name}} {{user.last_name}}</td> 
    <td>{{user.email}}</td>
    <td>{% if user.is_staff %} Admin {% else %} Practitioner {% endif %}</td>
    <td><a class="openButton" onclick="openForm()">Edit</a></td>
    <td><a href="{% url 'delete_user' user.id %}" class="openButton">Delete</a></td>
</tr>
{% endfor %}

EDIT

In the tutorial guy is using this url

url(r'^delete_user/<str:pk>', views.delete_user, name='delete_user')

but you are using

url(r'^delete_user/<int:pk>', views.delete_user, name='delete_user')
Deepak Tripathi
  • 3,175
  • 1
  • 8
  • 21