0
votes

I created class based view to access uid and token . Here I create one web page which have one button of activate user. I am sending one uid and token to user email.

I created class based view to get uid and token. I am sending email on user gmail account. where user get link for activate his account.

Email looks like this :

You're receiving this email because you need to finish activation process on 127.0.0.1:8000.

Please go to the following page to activate account:

http://127.0.0.1:8000/activate/Mg/ata7ek-01e823899301fe357286112596a25655

Thanks for using our site!

The 127.0.0.1:8000 team

....

But now I wish to change this content/template of email for activate account . How can I change this template in django

Here is my djoser setting

    DJOSER = {
    'LOGIN_FIELD': 'email',
    'USER_CREATE_PASSWORD_RETYPE': True,
    'USERNAME_CHANGED_EMAIL_CONFIRMATION': True,
    'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,
    'SEND_CONFIRMATION_EMAIL': True,
    'SET_USERNAME_RETYPE': True,
    'SET_PASSWORD_RETYPE': True,
    'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
    'USERNAME_RESET_CONFIRM_URL': 'email/reset/confirm/{uid}/{token}',
    'ACTIVATION_URL': 'activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,

    'SERIALIZERS': {
        'user_create': 'user_profile.serializer.UserSerializer',
        'user': 'user_profile.serializer.UserSerializer',

    }
}

views.py

class UserActivationView(View):
    def get (self, request, uid, token):
        return render(request, 'activate_user.html') 
    
    def post (self, request, uid, token):
        protocol = 'https://' if request.is_secure() else 'http://'  
        web_url = protocol + request.get_host() + '/'
        activate_url = "users/activation/"
        post_url = web_url + AUTHENTICATION_BASE_ROUTE + activate_url 
        response = requests.post(post_url, headers={'content-type':'application/json'}, 
        data = json.dumps({'uid': uid, 'token': token})

        if response.status_code == 204: 
            return render(request,"success.html")

        
        else:
            return render(request,"activation_failed.html")

How can I change it ?

1
Show us the views.pyRvector
updated in questionShweta Shinde

1 Answers

0
votes

It is clear, you just have to override activate_user.html template (djoser/templates/email/).

class UserActivationView(View):
    def get (self, request, uid, token):
        return render(request, 'activate_user.html')

Another option is create a new template in this directory and change the last line of the View to use it.

return render(request, 'new_activate_user.html')

Hopefully help you!