No reversematch error eventhough pk is imported - python

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

Related

Django: Problem with passing parameters from a template {% url %} to a view

I have this urlpath:
path('download/<str:fpath>/<str:fname>', views.download, name='download'),
And this is the view:
def download(request, fpath, fname):
# some code
In template, I have this href tag and I want to pass those strings as arguments to the download view.
click me
But I get this error:
NoReverseMatch at /
Reverse for 'download' with arguments '('lms/static/lms/files/homework/Math 1/3/3', 'hmm.pdf')' not found. 1 pattern(s) tried: ['download/(?P<fpath>[^/]+)/(?P<fname>[^/]+)\\Z']
How can I fix this?
Url arguments of type str cannot contains / characters. You can see this in the error message which has translated your <str:fpath> to a regex:
tried: ['download/(?P<fpath>[^/]+)/(?P<fname>[^/]+)\\Z']
You should use a path converter for your case (see here).
For example:
path('download/<path:fpath>/<str:fname>', ...)

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.

Named url with kwargs issue

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 ?

NoReverseMatch django error multiple URLs same method

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?

Categories

Resources