[Answer]-NoReverseMatch found

1👍

You should add the username of the user to follow/unfollow:

{% url 'follow' user_to_follow.username %}

Change the urls.py to:

urlpatterns = patterns('myuserprofile.views',
         url(r'^(?P<username>[^/]+)/$', 'profile', name='profile'),
         url(r'^(?P<username>[^/]+)/follow/$', 'follow', name='follow'),
         url(r'^(?P<username>[^/]+)/unfollow/$', 'unfollow', name='unfollow'),
)

And the signature of the view should accept the username argument:

@login_required
def follow(request, username):
    myuser = request.user.id
    if request.method == 'POST':
        to_user = MyUser.objects.get(username=username)
        ...

0👍

You need to use namespaced URL.
In your case the URL unfollow should be referenced as <app_name>:unfollow.

0👍

URL namespaces allow you to uniquely reverse named URL patterns even
if different applications use the same URL names. It’s a good practice
for third-party apps to always use namespaced URLs (as we did in the
tutorial). Similarly, it also allows you to reverse URLs if multiple
instances of an application are deployed. In other words, since
multiple instances of a single application will share named URLs,
namespaces provide a way to tell these named URLs apart

have a look on this Here

you have to use URL namespaces

here is my

polls/urls.py

from django.conf.urls import patterns, url

from . import views

urlpatterns = patterns('',
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
    ...
)

so we have use like

{% url 'polls:index' %}

0👍

You were missing the slug in your template.

<form action="{% if relationship.status == 'F' %}{% url 'unfollow' %}{% else %}{% url 'follow' %}{% endif %}" method="POST">

It should be

<form action="{% if relationship.status == 'F' %}{% url 'unfollow' user.username %}{% else %}{% url 'follow' user.username %}{% endif %}" method="POST">
👤Rohit

Leave a comment