Open sandino opened 8 years ago
Thank you.
I got that finally. The problem was that I passed username as an argument while my username_field
is email. But if I put {% url 'imagestore:user' album.user.email %}
into template I get NoReverseMatch. To fix it we need to change the url config something like this
-url(r'^user/(?P<username>\w+)/albums/', AlbumListView.as_view(), name='user'),
+url(r'^user/(?P<username>[@\.\w]+)/albums/', AlbumListView.as_view(), name='user'),
so it can resolve url with email address in it. Same to the next line:
-url(r'^user/(?P<username>\w+)/$', ImageListView.as_view(), name='user-images'),
+url(r'^user/(?P<username>[@\.\w]+)/$', ImageListView.as_view(), name='user-images'),
Hm, I don't think it's a good idea. \w+@\w+(?:\.\w+)+
is a little hard to understand. Maybe you want to try to override this pattern for your project only?
See I changed it to [@\.\w]+
in my previous comment.
I've already overridden the pattern for my project.
But I think it would be nice for imagestore to allow email in url config since it uses username_field
variable, not just username
explicitly.
OK, thank you, we (@zeus, @GeyseR) will think about it.
I had few issues with url regex this night. Now I decided to use [\w|\W]+
that covers all cases.
Hi,
I have a custom user model CustomUser. On album list page under each album cover I put album user name with a link to
{% url 'imagestore:user' album.user.username %}
, and the url resolves correctly. But when I click the link I open Http404 page with No CustomUser matches the given query message. Using pdb debugger I found that in this line the specified user cannot be found as it is being looked for using django.contrib.auth.models.User while it is an instance of the custom model.