Error: NoReverseMatch at /myplaylists/
Reverse for 'create_playlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
My urls.py:
url(r'^create_playlist/$', views.create_playlist, name='create_playlist'),
On my index page, im trying to reference that url using :
Create playlist
If you are using namespacing in your application, you need to reference the namespace in your url template tag like so:
{% url 'name_of_namespace:name_of_view' %}
Related
I'm building a django blog app. But, when I'm trying to build detail pages for blog posts, I'm getting this error:
NoReverseMatch at /
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['posts/(?P<pk>[0-9]+)/$']
This is my post_detail view function:
def post_detail(request,post_id):
post = get_object_or_404(Post, id=post_id)
return render(request, 'blog/detail.html',{'post':post})
My url route:
path('posts/<int:post_id>/',views.post_detail,name='detail'),
And the line that links to detail page:
<p class="lead my-3">{{ latest_post.title }}</p>
I don't think I should have any error in this. Where am I going wrong?
EDIT
I solved this problem. It's just that when I was trying to add this "detail" link to the "latest_post" variable. But I had specified it only for "post" variable. I just replaced it with "post" and it worked!
Error while passing value to view from template using url
Error :
Error during template rendering
In template D:\TONO\DJANGO_TASK\user_auth\templates\auth_app\other-user-listing.html, error at line 114
Reverse for 'add_to_group' with arguments '(name: Administrator,)' not found. 1 pattern(s) tried: ['auth_app\\/<str:username>/']
This my urls.py
url(r'^<str:username>/', views.add_to_group, name="add_to_group"),
This is the call from template
<i class="icon-plus">Add</i>
In your call from template see if you do this if that solves the problem, I remember I was facing this issue and this is what I did:
The syntax for specifying url is {% url namespace:url_name %}. So, check if you have added the app_name in urls.py.
Your url defines a named argument for the url "add_to_group". You should pass this argument as a keyword argument
{% url 'add_to_group' username=username %}
You are mixing the new and old style urls. To use the new style you should use path
path('<str:username>/', views.add_to_group, name="add_to_group"),
Error corrected using :
url(r'^auth_app/add_to_group/(?P<username>[-\w]+)/$', views.add_to_group, name='add_to_group'),
I'm trying to do a reverse like this:
print reverse("shows-view")
This is in my urls.py:
url(r'^shows/(\d+)$', views.show_details, name="shows-view"),
Whenever I try to do that, it just returns:
Reverse for 'shows-view' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['shows/(\\d+)$']
But if I try to access the page directly (http://localhost/shows/3333) then it works fine
But if I do a reverse for other views like this:
print reverse("shows-default-view")
with the following declaration in the same urls.py file:
url(r'^shows/', views.popular, name="shows-default-view"),
then it works fine. Does anyone have any idea why?
The URL in question accepts an argument (\d+) which you are not passing your reverse function. Just think: this is a details view, but which show do you want to display?
To fix, call reverse with the args parameter:
reverse("shows-default-view", args=[1]) # to show show with id of 1
In general for URL's like that, the recommendation is to have a named captured group:
url(r'^shows/(?P<pk>\d+)$', views.show_details, name="shows-view")
And then the call to reverse will be:
reverse("shows-default-view", kwargs={'pk': 1})
To use reverse in a template, just put the two arguments together:
{% url 'shows-view' 1 %}
Does anyone know how to make a reverse url lookup on a url with an include parameter? For example I have the following url:
url(r'^photos/', include('photos.urls'), name="photos"),
And in my view i want to access it as follows
def photos_redirect(request, path):
return HttpResponsePermanentRedirect(reverse('photos') + path)
But it get the following error:
Reverse for 'photos' with arguments '()' and keyword arguments '{}' not found.
You have to reverse to a single urlpattern. The photos URL pattern is including all the urlpatterns in photos.urls, so you have to choose which single URL you are wanting to direct to.
continuing question from here. after fixing the template according to #dannyroa - removing the quotes from the template name I still get NoReverseMatch error:
NoReverseMatch at /transfers/41/
Reverse for 'description_url' with arguments '(u'\u05ea\u05e7\u05e6\u05d9\u05d1 \u05d4\u05e9\u05db\u05e8 - \u05d1\u05d9\u05ea \u05d4\u05e0\u05e9\u05d9\u05d0',)' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://127.0.0.1:8000/transfers/41/
Django Version: 1.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'description_url' with arguments '(u'\u05ea\u05e7\u05e6\u05d9\u05d1 \u05d4\u05e9\u05db\u05e8 - \u05d1\u05d9\u05ea \u05d4\u05e0\u05e9\u05d9\u05d0',)' and keyword arguments '{}' not found.
the template now:
<a href='{% url description_url transfer.description %}'>{{transfer.description}}</a>
the urlconf:
url(r'^description/(?P<description>[\w ]+)/$',
'transfers.views.description_ListView',
name = 'description_url')
the view:
def description_ListView(requesst,**kwargs):
template_name = 'transfers/description.html'
o = get_list_or_404(Transfer, description =kwargs['description'])
#print ('o:',o)
context_object_name = "transfer_name_list"
return render_to_response(template_name,{context_object_name:o,'description':kwargs['description']})
this problem is really starting to get me down. I know I can write a specific method on the Transfer Model (maybe with #permalink) returning the right url for each view. but this is a lot of work and certainly frustrating to do this only because of my miserable failure at using the {%url %} template tag
thanks for the help