Named url with kwargs issue - python

Can anyone explain to me what is happening here? In the same template I have the following:
Group
Group
The top url works fine while the bottom errors out the entire page with:
Reverse for 'triage' with arguments '()' and keyword arguments '{u'group_id': 7}' not found. 0 pattern(s) tried: []
Any ideas?

The documentation mentions that:
This {% url ... as var %} syntax will not cause an error if the view is missing.
That is why the 1st view errors out the page while the second one works.
In any case, probably there is an error in your url pattern - can you show us your urls.py ?

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.

Cannot properly generate URL with captured arguments using {% url %} template tag

I'm running into an issue with supplying captured URL parameters through template tags. I have a URL dispatch with a captured parameter that hands off to another URL dispatch with include() that does not have any captured parameters:
nodemanager.urls:
url(r'^(?P<node_id>\d+)/rank/', include('ranking.urls')),
ranking.urls:
url(r'^setup$', views.setup, name='setup'),
I am using {% url 'setup' node_id=node.id %} in my template which creates the error:
TypeError at /stage1/node/5/rank/setup
setup() got an unexpected keyword argument 'node_id'
If I take out the keyword argument and just use: {% url 'setup' %}, the landing page fails to load and I get the (predictable) error:
NoReverseMatch at /stage1/
Reverse for 'setup' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) >tried: ['stage1/node/(?P\d+)/rank/setup$']
I know that I need to supply the parameter for node_id to properly reverse the URL. However, the named url "setup" in my ranking app doesn't take any parameters, but the URL that includes it (in the nodemanager app) does.
How would I properly pass the node_id keyword argument using a template tag that points to stage1/node/5/rank/setup, i.e. something of the form {% url 'setup' ... %}. Can I do this?
Let me know if I need to post more context code; I tried to include (what I thought) are the relevant parts.
The original error is not due to the URL reversing, but comes when the view is actually called. This is probably because you have not declared it to take a node_id argument. It should be like this:
def setup(request, node_id):
...
Once you've fixed that, the original url tag syntax should work.

Django: password reset ReverseMatch error

I'm having trouble getting password_reset_confirm to work. I have looked at numerous solutions, but none seem to be working for me.
urls.py: (in particular, the third line)
(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name="reset_password"),
(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', name="reset_password"),
(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)-(?P<token>,+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
the password_reset_email.html:
{% load url from future %}
{% autoescape off %}
Someone asked for password reset for email {{ email }}. Follow the link below:
{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}
{% endautoescape %}
Everything seems to be working fine, until I submit my e-mail and get the following error:
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'OQ', u'token': u'3n2-0fee9d3f98dad36e63d8'}' not found. 2 pattern(s) tried: ['/$reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'reset/(?P<uidb64>[0-9A-Za-z_\\-]+)-(?P<token>,+)/$']
I am using Django 1.6.
Any help is much appreciated! Thanks!
You can see from the exception what's going on, although it's a little hard to spot. If you look at what patterns it tried:
2 pattern(s) tried: ['/$reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'reset/(?P<uidb64>[0-9A-Za-z_\\-]+)-(?P<token>,+)/$']
You should notice that the first pattern is the one that should generally match, in the sense that it accepts a token with a - in it. But it has a stray $ prepending the rest of its content, so actually it can't match anything:
'/$reset/...'
You don't show the urls.py line that establishes that pattern - the third line you refer to can only match a token consisting of nothing but commas:
(?P<token>,+)
So while I can safely say that you need to correct your urls.py, I cannot say exactly where you need to correct it. If you intend to match that urls.py line, you should update the token group regexp to accept your actual token values, and should figure out why the other one is around to match at all. That said, if - is a valid character to appear as part of your token I think you'll find it easier overall to use / as a divider between your uidb64 field and your token, as your first regexp does except for the stray $.

Django url template confusion

Okay I am having a bit of an issue.
I want to create a button with a link, and right now I am using action={% url views.contest_overview %} in hopes that the reverse lookup by Django will match (r'^category/$', views.contest_overview), in my urls.py. However, this is not working and I can't figure out the proper nomenclature, despite numerous guesses.
The error I get (with my best guess above) is:
Caught NoReverseMatch while rendering: Reverse for
'views.contest_overview' with arguments '()' and keyword arguments
'{}' not found.
Thank you very much for your time!
Use the application name in the url tag, e.g. {% url myapp.views.contest_overview %}
This is what I usually do; I give names to my url. For example:
url(r'^account/register/$', 'someapp.views.register_view', name='account_register'),
Therefore in template, I can do this:
{% url account_register as url_acc_register %}
<html>
..
..
Some link

Categories

Resources