No Reverse Match Exception

62 views
Skip to first unread message

yingi keme

unread,
Dec 16, 2017, 4:22:49 AM12/16/17
to Django users
I am using the django generic UpdateView

class UserUpdate(UpdateView):
    model = User
    fields = ['first_name', 'last_name', 'email', 'username']
    template_name = 'Core\MyUpdate.htm'

And my url pattern is this:

url(r'^UpdateMe/(?P<pk>\d+)/$', UserUpdate.as_view(), name='Update')

However, this url  Core/UpdateMe/34/ doesnt seem to match and it gives this error

NoReverseMatch at /Core/UpdateMe/34/

Reverse for 'Update' with arguments '('',)' not found. 1 pattern(s) tried: ['Core/UpdateMe/(?P<pk>\\d+)/$']


Любопытный Енот

unread,
Dec 16, 2017, 11:01:15 AM12/16/17
to Django users
try fix your pattern to
r'^/Core/UpdateMe/(?P<pk>\\d+)/$'


суббота, 16 декабря 2017 г., 12:22:49 UTC+3 пользователь yingi keme написал:

yingi keme

unread,
Dec 17, 2017, 3:31:13 AM12/17/17
to django...@googlegroups.com
The problem is that, it works perfectly when i put the number on the template like this

<a href="{% url 'Update' 34 %}">Update</a>

But when i do 

<a href="{% url 'Update' pk=User.id %}">Update</a>

It gives the No Reverse Error. I dont seem to understand why

Yingi Kem
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/867231ed-4b2e-4882-87c5-d482579dc182%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pradam programmer

unread,
Dec 17, 2017, 3:36:56 AM12/17/17
to django...@googlegroups.com
From this:
<a href="{% url 'Update' pk=User.id %}">Update</a>
Change to this:
<a href="{% url 'Update' pk={{User.id}} %}">Update</a>

On 17-Dec-2017 2:00 PM, "yingi keme" <ying...@gmail.com> wrote:
The problem is that, it works perfectly when i put the number on the template like this

<a href="{% url 'Update' 34 %}">Update</a>

But when i do 

<a href="{% url 'Update' pk=User.id %}">Update</a>

It gives the No Reverse Error. I dont seem to understand why

Yingi Kem

On 16 Dec 2017, at 11:18 AM, Любопытный Енот <kpbl...@gmail.com> wrote:

try fix your pattern to
r'^/Core/UpdateMe/(?P<pk>\\d+)/$'


суббота, 16 декабря 2017 г., 12:22:49 UTC+3 пользователь yingi keme написал:
I am using the django generic UpdateView

class UserUpdate(UpdateView):
    model = User
    fields = ['first_name', 'last_name', 'email', 'username']
    template_name = 'Core\MyUpdate.htm'

And my url pattern is this:

url(r'^UpdateMe/(?P<pk>\d+)/$', UserUpdate.as_view(), name='Update')

However, this url  Core/UpdateMe/34/ doesnt seem to match and it gives this error

NoReverseMatch at /Core/UpdateMe/34/

Reverse for 'Update' with arguments '('',)' not found. 1 pattern(s) tried: ['Core/UpdateMe/(?P<pk>\\d+)/$']


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Andréas Kühne

unread,
Dec 17, 2017, 3:45:21 AM12/17/17
to django...@googlegroups.com
2017-12-17 9:35 GMT+01:00 pradam programmer <pradam.pr...@gmail.com>:
From this:
<a href="{% url 'Update' pk=User.id %}">Update</a>
Change to this:
<a href="{% url 'Update' pk={{User.id}} %}">Update</a>


That will not work and isn't recommended. Everything within {% %} is python code already, so you don't need to interpolate again. I don't even think that will work.

Unfortunately I don't have any suggestions to get it working either...

Regards,

Andréas


 
On 17-Dec-2017 2:00 PM, "yingi keme" <ying...@gmail.com> wrote:
The problem is that, it works perfectly when i put the number on the template like this

<a href="{% url 'Update' 34 %}">Update</a>

But when i do 

<a href="{% url 'Update' pk=User.id %}">Update</a>

It gives the No Reverse Error. I dont seem to understand why

Yingi Kem

On 16 Dec 2017, at 11:18 AM, Любопытный Енот <kpbl...@gmail.com> wrote:

try fix your pattern to
r'^/Core/UpdateMe/(?P<pk>\\d+)/$'


суббота, 16 декабря 2017 г., 12:22:49 UTC+3 пользователь yingi keme написал:
I am using the django generic UpdateView

class UserUpdate(UpdateView):
    model = User
    fields = ['first_name', 'last_name', 'email', 'username']
    template_name = 'Core\MyUpdate.htm'

And my url pattern is this:

url(r'^UpdateMe/(?P<pk>\d+)/$', UserUpdate.as_view(), name='Update')

However, this url  Core/UpdateMe/34/ doesnt seem to match and it gives this error

NoReverseMatch at /Core/UpdateMe/34/

Reverse for 'Update' with arguments '('',)' not found. 1 pattern(s) tried: ['Core/UpdateMe/(?P<pk>\\d+)/$']
 
You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/867231ed-4b2e-4882-87c5-d482579dc182%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/249DD07C-736B-4861-A32B-2C00FC04E960%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

yingi keme

unread,
Dec 17, 2017, 5:26:33 AM12/17/17
to django...@googlegroups.com
So is there no way out? I am really confused how to go on with this

Yingi Kem
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

James Schneider

unread,
Dec 17, 2017, 6:04:17 AM12/17/17
to django...@googlegroups.com


On Dec 17, 2017 12:30 AM, "yingi keme" <ying...@gmail.com> wrote:
The problem is that, it works perfectly when i put the number on the template like this

<a href="{% url 'Update' 34 %}">Update</a>

But when i do 

<a href="{% url 'Update' pk=User.id %}">Update</a>

It gives the No Reverse Error. I dont seem to understand why

Instead of User.id, try user.id, capitalization matters.

{% url 'Update' pk=user.id %}

The default context variable provided by django.contrib.auth is 'user' in the template context, not 'User', which I'm assuming you are using.

Since the 'User' variable does not exist in your template context, it resolves to '' (empty string), meaning that you are passing a PK of '' to your view, which it is unhappy with. This is evidenced in the error message you originally posted with an empty string showing as the argument to the URL resolver:

Reverse for 'Update' with arguments '('',)' not found. 1 pattern(s) tried: ['Core/UpdateMe/(?P<pk>\\d+)/$']

HTH,

-James

James Schneider

unread,
Dec 17, 2017, 6:15:05 AM12/17/17
to django...@googlegroups.com



<a href="{% url 'Update' pk=User.id %}">Update</a>

It gives the No Reverse Error. I dont seem to understand why

Instead of User.id, try user.id, capitalization matters.

Trying not to confuse things, but in this instance you may instead want to use object.id, since you may be referring to a different User object than the one that is logged in. I made an assumption that the view will be only modifying the logged in user.

-James

yingi keme

unread,
Dec 17, 2017, 6:55:12 AM12/17/17
to django...@googlegroups.com
You nailed it james. It worked for me. The capitalization matters.

Thanks James..!!!

Yingi Kem
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages