[Answered ]-Reverse for 'user-profile' with arguments '('',)' not found. 1 pattern(s) tried: ['profile/(?P<pk>[^/]+)/\\Z']

1👍

It may be because of forgetting a simple space, of course, I encountered this error just today and two hours later I realized that my problem is a simple space… space between equal sign and variable….

{% if room.host.username == request.user.username %}
<div>
    <a href="{% url 'update-room' room.id %}">Edit</a>
    <a href="{% url 'delete-room' room.id %}">Delete</a>
</div>
{% endif %}

0👍

It is because pk is of int type not str type.

Simply change your all routes to <int:pk>/.

Try below code:

Urls.py

urlpatterns = [
    path('login/', views.loginPage, name="login"),
    path('logout/', views.logoutUser, name="logout"),
    path('register/', views.registerPage, name="register"),


    path('', views.home, name="home"),
    path('room/<int:pk>/', views.room, name="room"),
    path('profile/<int:pk>/', views.userProfile, name='user-profile'),

    path('create-room/', views.createRoom, name="create-room"),
    path('update-room/<int:pk>/', views.updateRoom, name="update-room"),
    path('delete-room/<int:pk>/', views.deleteRoom, name="delete-room"),
    path('delete-message/<int:pk>/', views.deleteMessage, name="delete-message"),

Note: Always give / at the end of every route in path function.

Note: Function based views are generally written in snake_case not camelCase, so it will better if you change your view name to user_profile instead of userProfile.

0👍

I think the error is happening on this line in feed_component.html:

<a href="{% url 'user-profile' room.host.id %}">@{{room.host.username}}</a>

room.host.id is resolving to a blank string, which is caused by a room object with a null host field.

The Room model definition does allow for a null host:

class Room(models.Model):
    host = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)

0👍

This problem might have occurred because you deleted a user who was having rooms. since you deleted the user’s room which sets the room’s host to null
"host = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)"

I have just resolved this problem; it seems to be a problem due to your rooms not having any host. that’s why it is not able to find the user profile for a particular room. just go to your Django admin and check all your room’s hosts, if it is null then set any user to its host problem will be solved.

Leave a comment