I'm setting the authentication process in my Django project.
In my password_reset_email.html I have set the following code:
Someone requested a password reset for the account associated with the email {{email}}.
If you haven't changed any passwords, I will ignore this email.
Follow the link in case you proceed:
{{protocol}}://{{domain}}{% url 'password_reset_confirm' uidb64=uid token=token %}
But when I send the e-mail, the hyperlink does not work; there appears only the text of the link.
How could get a working hyperlink?
The relevant docs for you would be PasswordResetView.html_email_template_name:
html_email_template_name: The full name of a template to use for generating a text/html multipart email with the password reset link. By default, HTML email is not sent.
With this, your code could look something like this:
path(
'accounts/password_reset/',
PasswordResetView.as_view(
html_email_template_name='my_email_template.html')),
See this answer of a very similar question.
Related
I have used Django's built-in password reset functionality. everything is working fine but when I open the password reset link from Gmail browser redirects me to Django's built-in "password_reset_confime " template instead of my custom template
I don't know where I have done mistake in rendering custom template please help me to do that its really appreciated
usrl.py Code
app_name="accounts"
urlpatterns=[
path('password_reset/',auth_views.PasswordResetView.as_view( template_name='password_reset.html', success_url=reverse_lazy('accounts:password_reset_done')),name='password_reset'),
path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(template_name='password_reset_done.html'), name='password_reset_done'),
path('password_reset_confirm/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html',success_url=reverse_lazy('accounts:password_reset_complete')),name='password_reset_confirm.html'),
path('password_reset_complete/', auth_views.PasswordResetCompleteView.as_view(template_name='password_reset_complete.html'), name='password_reset_complete'),
]
And I also want to implement a feature while entering an email id into the input field, I want to check if the user's entered email exists or not, if do not exist I want to show an error message "this email id is not existed"
please help me to implement this feature and provide a solution for rendering my custom password_reset_confirm.html and password_reset_complete.html pages
I am working with django and react and developing a multi tenant application where each subdomain in django is a different company. Using rest framework.
At user registration(company wise user) a confirmation email is send to each user to activate their account.
The email send to users are in the format of
http://company_code.localhost.com:8000/rest-auth/account-confirm-email/key
subdomain wise. After some search i came to know this goes from allauth, send_confirmation_message.text file and in the form of {{activate_url}}
for activating the account from react what i did was changed the default 'send_confirmation_message.txt' file of allauth as :
'http://localhost:3000/verify-email?key={{key}}' -- react
now i automatically filter my key from url on react and post to backend, and activate the account,
the manual part still is getting company code from the url which django send in the email.
Again i have read about template filter tag but can not use.
So how can i use filter on {{activate_url}} which is
http://company_code.localhost.com:8000/rest-auth/account-confirm-email/key
to get my company_code and send to react in the form of url.
Getting company_code is important as users are company wise and react should post to a specific company.
Or My approach is wrong and should try something other ?
Thanks
I made it work..
{% blocktrans %} in email_confirmation_message.txt was not allowing me to apply any filer on {{activate_url}} or add any new block.
I removed it and changed the url which user receive in email for activating the account.
The new url is :
http://front-end.com/verify-email/?id={{key}}&id1={{activate_url|slice:"7:12"}}
subdomain is always of 5 character,in my case.
and it takes me to my front end, automatically activate the account on componentDidMount and redirect to login.
ps: blocktrans will not allow to apply any filter, add new block.
still don't know what blocktrans is, if anyone can provide detail.
Thanks
I am trying to send emails to my clients using django's send_mail function.
I have configured my email host using a gmail account.
This is how I send my email:
send_mail(cv.QT_CONFIRMATION_MAIL_TITLE[lan], cv.QT_CONFIRMATION_MAIL[lan].format(str(uid, encoding="utf-8"), token),
'mygmail#gmail.com', [useremail], fail_silently=False,
html_message=cv.QT_CONFIRMATION_MAIL[lan].format(str(uid, encoding="utf-8"), token))
this html_message has an anchor tag in it which links to the activation link. In gmail clients the link works, but when I try this in yahoo emails the link is empty.
it is shown in html like this:
<a rel="nofollow"> click here </a>
what should I do?
I'm a little bit confused by the configuration variable ACCOUNT_CONFIRM_EMAIL_ON_GET. (docs)
If a user clicks on an activation link in an email, wouldn't the request have to be a get request? (Surely I'm wrong or missing something).
From my testing, if I leave ACCOUNT_CONFIRM_EMAIL_ON_GET set to False, when I click on the activation link from my email my account does not get activated. What am I missing here?
When a user is registered an url to confirm the e-mail address is generated. Eg:
http://www.example.com/accounts/confirm-email/iq4ma0qw6fqazui7ilwd4b3vftg/
With ACCOUNT_CONFIRM_EMAIL_ON_GET set to True the user will confirm the e-mail just by clicking the link. This happens because by clicking on the link, he will request the url (GET) and therefore, allauth will mark the e-mail address as confirmed because a GET for this url was received.
With ACCOUNT_CONFIRM_EMAIL_ON_GET set to False, when the user clicks on the link, a page will be loaded where there will be a button "Confirm e-mail address" or something like this. Then the user has to click on that button that will generate a POST request that will confirm the e-mail. This happens because allauth will mark the e-mail address as confirmed only on POST and not on GET requests to the e-mail confirmation url.
If you take a look at the source, you can see that the arguments passed to the view from the URL will be redirected to the post() method, meaning the user will not see a confirmation screen.
https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py#L213
I have a question: how to get the current path of the url. Let's say, I have 3 navigation bars, about , blog and contact page. In each page, I have facebook, twitter and a manual email a friend button. When I clicked the email a friend button, and the current URL is www.example.com/about, the current URL is now already www.example.com/emailafriend. How can I get the www.example/about? Also in blog and contact. Please help me. Thanks.
How does your email a friend button work? Is it a django view that takes the current URL and emails it? If so, you don't want the "current" URL, which, as you note, is actually the email a friend URL. What you want to do is pass the URL you want to share as a URL parameter, ie:
/share?url=http://www.example.com/blog
Adding more info based on comments:
When I was referencing URL above, I was not referring to your django URL configuration. Let's take a step back.
On your About page you have a link to email a friend, right? That link is probably generated in your template, but it's the same on every page. Something like:
Email a friend
Instead of this, try this:
Email a friend
Now you need to make your email_a_friend view handle this. It can get the url via
request.get('url', '').
Some additional information:
You might want to escape the {{ request.get_full_path }} function so that it's escaped and URL safe, then you'll have to unescape it in your view. Once you get the URL back to your view, you can do as you please with it.
{{ request.get_full_path|urlencode }}
Try using Relative URLs like for example From www.example.com/about to get to www.example.com/email use /email. Using relative urls is the simplest solution .
Take a look at this.
Absolute vs relative URLs
It sounds like your want to get the referring URL (the URL that sent you to the current page). That is available to you in the request object, although it is not 100% reliable:
request.META['HTTP_REFERER']
See the documentation on HttpRequest objects for more information.