Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom users not found #56

Open
sandino opened this issue Aug 5, 2015 · 6 comments
Open

Custom users not found #56

sandino opened this issue Aug 5, 2015 · 6 comments

Comments

@sandino
Copy link

sandino commented Aug 5, 2015

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.

@sandino sandino changed the title User albums or images are not found for custom user model Custom users not found Aug 5, 2015
@lampslave
Copy link
Contributor

Thank you.

@sandino
Copy link
Author

sandino commented Aug 5, 2015

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'),

@lampslave
Copy link
Contributor

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?

@sandino
Copy link
Author

sandino commented Aug 5, 2015

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.

@lampslave
Copy link
Contributor

OK, thank you, we (@zeus, @GeyseR) will think about it.

@lampslave lampslave reopened this Aug 5, 2015
@sandino
Copy link
Author

sandino commented Aug 6, 2015

I had few issues with url regex this night. Now I decided to use [\w|\W]+ that covers all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants