I have this link in a template:
Item 1
and this url in the urls.py
url(r'item/(?P<id>)/$', show_item, name="page_item")
however, this error occurs:
Reverse for 'show_item' with arguments '(63L,)' and keyword arguments '{}' not found.
I looked at this question:
how to get python to not append L to longs or ignore in django template
but it did not help.
Is there another way to use the primary key, which is an integer, in constructing URLs in templates?
The URL name doesn't match. Change the template to be:
Item 1
It should be page_item not show_item in template.
Related
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 have such url pattern:
url(r'^drinks/(?P<drink_name>\D+)/',TemplateView.as_view(template_name='drinks/index.
html'),name="drink")
How can I get access to drink_name parameter value in template.
You can access the variable of the URL in the template as follows:
{{view.drink_name}}
regards
I'm using an App that configures some Admin URLs as:
#admin.py....
def get_urls(self):
urls = super(FormAdmin, self).get_urls()
extra_urls = [
url("^(?P<form_id>\d+)/entries/$",
self.admin_site.admin_view(self.entries_view),
name="form_entries"),
#......
]
return extra_urls + urls
I'm having trouble using template tags to get a URL corresponding to that, in one of my templates. I'm trying stuff like:
4-Entries
(Where forms is the App's label). I keep running into the No Reverse Match type of errors:
NoReverseMatch at /polls/ Reverse for 'forms_form_entries' with
arguments '(4,)' and keyword arguments '{}' not found. 0 pattern(s)
tried: []
What am I missing that makes the tag work correctly?
Try this in html
4-Entries
Your url pattern name form_entries doesn't match forms_form_entries from the URL tag. Django does not automatically prefix the pattern name with <app_name>_ as you appear to be expecting.
Change one of them so that they match.
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.