I'm trying to build a login system where the user - after sign up - needs to click on a link an an activation email. I create the token in a method:
def get_context_data(
self, request, user, context=None):
if context is None:
context = dict()
current_site = get_current_site(request)
if request.is_secure():
protocol = 'https'
else:
protocol = 'http'
token = token_generator.make_token(user)
uid = urlsafe_base64_encode(
force_bytes(user.pk))
context.update({
'domain': current_site.domain,
'protocol': protocol,
'site_name': current_site.name,
'token': token,
'uid': uid,
'user': user,
})
return context
The problem here is that the generated token looks like this:
http://127.0.0.1:8000/user/activate/b'NjA'/4t8-9fad2c2dc78ecf8a1228/
The URL is not working because urlsafe_base64_encode(force_bytes(user.ok))
gennerates some weired character combinations that dont work in the url. I get the following error.
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/user/activate/b&
As you can see, the url is cut off after the #&.
How can I encode the user.pk
in a way that will work in the url?