Search code examples
djangodjango-templatesdjango-urlsdjango-url-reverse

Reverse for 'userprofile' not found. 'userprofile' is not a valid view function or pattern name


When i write in urls.py app_name = 'user_homeview' then occure error in header.html how i solve this error can you tell me i couldn't solve error yet please tell me..in below html file where wrote href="{%url 'userprofile' i.user %}" in code occure error after write app_name='' in urls.py please tell me how i solve

head.html
 {% for i in userpofile %}

                  <img src="{{i.userImage.url}}" href="{%url 'userprofile' i.user %}" class="align-self-start   img-responsi img-circle tm-border " alt="...">
                  <a href="{%url 'userprofile' i.user %}" >{{i.user}}</a>&nbsp
            {% endfor %}


urls.py

app_name = 'user_homeview'

urlpatterns = [



    path('', views.user_home,name='e'),
    path("user/follow/<str:username>", views.follow, name="follow"),
    path('postWrite', views.postWrite ,name='post'),
    path('post', views.post ,name='post'),
    path('like_dislike', views.likePost ,name='like_dislike_post'),
    path('slug/comment', views.comment ,name='comment'),
    path("delete/<int:ID>",views.delpost,name="delpost" ),
    path("search/", Search_User.as_view(), name="search_user"),
    path("<str:username>",views.userProfile,name="userprofile" ),
    path("<str:username>/edit", EditProfile.as_view(), name="editprofile"),
    

Solution

  • Since you declared the app_name you need to use that to construct the URL. So the correct way would be:

    {% url 'user_homeview:userprofile' i.user %}