1👍
✅
You are using standart user, so User pk is always int
, if you want to select user by username you have to rewrite get_object
method of your view, like this:
class UserDetailView(DetailView):
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
username = self.kwargs.get('username', None)
return queryset.get(username=username)
and add username
to url:
url(r"^(?P<username>\w+)/$", UserDetailView.as_view(), name="test.html"),
0👍
Even without knowing regex, it should be clear to you that you haven’t got a URL matching “/abc12345/”, you only have one matching “/user/12345”. You’ve hard-coded that “user” prefix.
The other problem is that your regex only accepts digits (\d+
) rather than alphanumeric characters (\w+
).
- [Answer]-Dajax not working
- [Answer]-Django model for time-table like objects
- [Answer]-_store_result() got an unexpected keyword argument 'request' in celery
- [Answer]-Check that the username already exists in AJAX
Source:stackexchange.com