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
.
- [Answer]-Django paypal notify_url not configured correctly or working
- [Answer]-Is it possible to ignore a system check error in Django 1.7+
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' %}
- [Answer]-Seeking help in designing django models
- [Answer]-This XML file does not appear to have any style information associated with it. The document tree is shown below.2
- [Answer]-Django How to iterate over list returned from ldap to save new object
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">
- [Answer]-Many to Many and Foreign Key relations in django admin
- [Answer]-Django Rest Framework: return ForeignKey as array, getting "TypeError: object is not iterable"?