NoReverseMatch django error multiple URLs same method - python

error message:
ExceptionType: NoReverseMatch
Exception Value: Reverse for 'darts.teams.views.expanded_details' with arguments '(u'RightFlights',)' and keyword arguments '{}' not found.
in the template:
Expanded Details
in urls.py
urlpatterns = patterns('darts.teams.views',
url(r'^(?P<teamname>.*?)/expanded_details/$', 'team_details', {'expanded': True}, "expanded_details"),
url(r'^(?P<teamname>.*?)/details/$', 'team_details', name="team_details"),
url(r'^(?P<teamname>.*?)/add_player/$', 'team_add_player', name="team_add_player"),
url(r'^(?P<teamname>.*?)/add_player/confirm/$', 'team_add_player',"team_add_player_confirm"),
)
The additional URLs in urls.py all render fine, but the 'expanded_details' one is throwing the error.
Why is this one different than the others? Am I missing something blatant?

update
The error says "Reverse for 'darts.teams.views.expanded_details' failed", but it should be 'darts.teams.views.team_details' or 'expanded_details'. The first form is the path to view, the latter is the name of the named URL.
You could check the value of expanded_details inside the templatetag to ensure it is resolved to one of the correct values above, or follow slackjake's suggestion: use 'expanded_details' (note the single quote) directly.
(?P<teamname>.*? is invalid, maybe you mean (?P<teamname>.*?)?
Also, what does lib.url do?

Related

No reversematch error eventhough pk is imported

I got a No reverseMatch Error evnthough pk has been imported.
Traceback:
Reverse for 'profile_page' with no arguments not found. 1 pattern(s) tried: ['profile_page/(?P<pro>[^/]+)$']
urls.py:
path('profile_page/<str:pro>', UserProfileView, name='profile_page'),
Reverse for 'profile_page' with no arguments not found. 1 pattern(s) tried: ['profile_page/(?P<pro>[^/]+)$']
Your Error Traceback clearly says that no arguments are found for profile_page route.
Since your url route for profile_page accepts a string, you need to pass one
urls.py
path('profile_page/<str:pro>', UserProfileView, name='profile_page'),
Wherever you are navigating to profile_page in your HTML code. you have to pass a string along with it.
I suppose you are using this route to display the profile page of a user, then use this - {% url 'profile_page' <some_user_name> %}
Eg: User

Celery-Progress-Bar Not Working in Django

I am trying to use celery-progress module to show the user the progress of the task, since it takes lot of time to complete the task. However, after following the instructions on https://github.com/czue/celery-progress,I am seeing the following error on the front-end:-
NoReverseMatch at /netadc/arista/views/getFabListArista/TRCW/
Reverse for 'task_status' with arguments '('',)' not found. 1 pattern(s) tried: [u'celery_progress/(?P<task_id>[\\w-]+)/$']
Request Method: GET
Request URL: http://x.x.x.x/netadc/arista/views/getFabListArista/TRCW/
Django Version: 1.11
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'task_status' with arguments '('',)' not found. 1 pattern(s) tried: [u'celery_progress/(?P<task_id>[\\w-]+)/$']
The URL pattern on the front-end var progressUrl = "{% url 'celery_progress:task_status' task_id %}"; does not work.
When I change it to var progressUrl = "{% url 'celery_progress:task_status' 'task_id' %}"; i do not get the error, but no tasks are running.
Any experts on django/python, please help.
You have to add the url mapping of celery_progress to your main urls.py. It's described in the Prerequisites section of the project's README.
Check here: https://github.com/czue/celery-progress/issues/27
this implies the task ID is blank. The best way to troubleshoot it is to try and figure out why it's blank. It can be because your backend isn't properly configured so the ID is not assigned/returned from the async call, because you're not passing it properly from the view to the template, because you're referencing the wrong variable in the template, etc.
I'd recommend you get to the bottom of why the ID is blank and that should hopefully lead you to the appropriate solution.

The Django test client: polls app part 5 NoReverseMatch

I am following the polls app and I am copying everything making sure I have 100% the same code they have but when I use
response = client.get(reverse('polls:index'));
I get a huge error and none of the notes are making sense to me. I was told by someone it has to do with my views.py but I looked and the Django site and it is 100% the same as mine. This was the error I got:
django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['pools/(?P<question_id>[0-9]+)/vote/$']
Looks like you have to specify the GET parameter named question_id on your URL.
The NoReverseMatch exception is raised by django.urls when a matching
URL in your URLconf cannot be identified based on the parameters
supplied.
The error said you have to provide a question id. I used 1 as an example.
http://localhost:8000/pools/1/vote/

How do I pass parameters via url in django?

I am trying to pass a parameter to my view, but I keep getting this error:
NoReverseMatch at /pay/how
Reverse for 'pay_summary' with arguments '(False,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['pay/summary/$']
/pay/how is the current view that I'm at. (that is the current template that that view is returning).
urls.py
url(r'^pay/summary/$', views.pay_summary, name='pay_summary')
views.py
def pay_summary(req, option):
if option:
#do something
else:
#do something else
....
template
my link
EDIT
I want the view should accept a POST request, not GET.
To add to the accepted answer, in Django 2.0 the url syntax has changed:
path('<int:key_id>/', views.myview, name='myname')
Or with regular expressions:
re_path(r'^(?P<key_id>[0-9])/$', views.myview, name='myname')
You need to define a variable on the url. For example:
url(r'^pay/summary/(?P<value>\d+)/$', views.pay_summary, name='pay_summary')),
In this case you would be able to call pay/summary/0
It could be a string true/false by replacing \d+ to \s+, but you would need to interpret the string, which is not the best.
You can then use:
my link

Django : NoReverseMatch for HttpResponseRedirect with kwargs

I'm getting the following error:
NoReverseMatch at /updatebooking/
Reverse for 'common.views.myview'
with arguments '()' and keyword arguments '{'msg': "hello", 'case':
'success'}' not found.
common/views.py
def view1(request):
...
return HttpResponseRedirect(reverse('common.views.view2', kwargs= {"msg":"hello","case":"success"}))
def view2(request,msg=None,case=None):
...
urls.py
url(r'^test1/$','common.views.view1',name='my_view1'),
url(r'^test2/$','common.views.view2',name='my_view2'),
This line reverse('common.views.view2', kwargs= {"msg":"hello","case":"success"}) is throwing the error.
The error comes only when I use kwargs. Following codes work:
return HttpResponseRedirect(reverse('my_view2'))
return HttpResponseRedirect(reverse('common.views.view2'))
Kindly help me resolve this.
When you are using reverse with kwargs parameters django tries to find a parameterized url route. In your example, matching route would be similar to
url(r'^test2/(?P<msg>\w+)/(?P<case>\w+)$','common.views.view2',name='my_view2')
Refer to reverse and URLDispatcher documentation for more details. Unfortunately, both URLDispatcher and reverse manuals are a little bit cryptic about this particuar feature.
Your url doesn't have msg or case parameter, that's why Django can't find it. See the paramenter slugin this example:
url(r'^(?P<slug>[^/]+)/$', 'test.views.detail', name="test-detail")
I believe that you're trying to pass a message/notification to another view. If that's the case, you should check the messages framework.

Categories

Resources