6๐
โ
Note:
path(..)
is available from Django-2.0.
The problem here is that friend
is not in the URL:
url(r'^add_friend/$', views.friend_add, name="add_friend"), # no parameter
You can for instance use the primary key (pk
) for the friend by specifying a path(..)
:
path(r'add_friend/<int:friend>/', views.friend_add, name="add_friend"),
In case you work with django-1.x, you can use url(..)
with a regex:
url(r'^add_friend/(?P<friend>[0-9]+)/$', views.friend_add, name="add_friend"),
And now we can use the primary key of the friend in the reverse url:
<input
type="button"
class="btn btn-info"
value="Add Friend"
onclick="location.href='{% url 'user:add_friend' friend=post.poster.pk %}';"
>
(multi-line to make it easier to read).
2๐
Your urlpattern shoul also have friend argument like this:
url(r'^add_friend/(?P<friend>[0-9]+)/$', views.friend_add, name="add_friend"),
This will allow you to pass integer ids of friend object to the url like this add_friend/12
.
๐คneverwalkaloner
- [Django]-Is there a Django template filter that turns a datetime into "5 hours ago" or "12 days ago"?
- [Django]-How do I retrieve a value of a field in a queryset object
- [Django]-Free CDN to store my images and css files for django on heroku
1๐
data-ajax-target call particular URL of Django in HTML button
<button type="Submit" value="Submit" class="btn btn-outline-light text-dark" data-ajax-target="{% url 'collections' %}?collection={{ collection.collectionID }}" }">
<span>{{ collection.choice_label }}</span>
</button>
๐คJhanvi Patel
- [Django]-When running Celery with Django's manage.py command, it returns a strange error
- [Django]-Django Queryset Count
- [Django]-Django โ Redirect user to "next" parameter after successful login
- [Django]-Extract only values without key from QuerySet and save them to list
- [Django]-Django caching for web applications
Source:stackexchange.com