Hi, I use Django 2 and I deploy my application with nginx-1.20.1 in windows server 2016.
so when I try to change a password I get this localhost as link
http://localhost:8080/reset/Ng/618-bdc5c678ddc95211c6a6/
So I need to change the localhost:8080
to my site adress (10.6.45.152
)
How I could do this.
then how I could change the function of sending because after months of trying with Django I am not able to receive the messages in my email!!!, however with my python script I can send emails
So how I can change Django default sending email function with mine?
All my best
If you are using the system-provided password reset views, see the docs for PasswordResetView , particularly the section on Email template context .
If you’re using something you’ve created, then you would need to use a similar facility.
We would need to see the code you’re using, along with the appropriate sections of your settings.
1 Like
this is the function that works
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
#from exchangelib import FileAttachment
def SendingEmail(request):
address_book = [request.GET.get('address_book')]
sender = request.GET.get('sender')
subject = request.GET.get('subject')
body = request.GET.get('body')
file_name = request.GET.get('file_name')
dir_path = request.GET.get('dir_path')
try:
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = ','.join(address_book)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
text=msg.as_string()
# Send the message via our SMTP server
s = smtplib.SMTP('XX.XXX.XXX.XX')
s.sendmail(sender,address_book, text)
s.quit()
messages={"message": 'successfully sent message to '+ str(address_book),"tag": 'success'}
except:
messages= {"message": 'Message Not sent!!!',"tag": 'danger'}
context= {
'messages':messages,
}
return render(request, 'Home/Emailing/part_Email.html',context)
python manage.py runserver 0.0.0.0:8000
I found the mistake I did, I’d deleted the EMAIL_HOST_USER and EMAIL_HOST_PASSWORD so I cqn send messages.
Now how I could change the localhost:8080 to 10.6.45.152.
I am trying to use this function PasswordResetView
but have some problems
Redirect the user to the login page, passing the given 'next' page.
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe="/")
return HttpResponseRedirect(urlunparse(login_url_parts))
# Class-based password reset views
# - PasswordResetView sends the mail
# - PasswordResetDoneView shows a success message for the above
# - PasswordResetConfirmView checks the link the user clicked and
# prompts for a new password
# - PasswordResetCompleteView shows a success message for the above
How are you trying to use it? Are you trying to use the PasswordResetView directly, or are you subclassing it with your own view? How are users accessing that view? Do you have a path
in your urls.py file for that view?
this function
class PasswordResetView(PasswordContextMixin, FormView):
email_template_name = "user/password_reset_email.html"
extra_email_context = None
form_class = PasswordResetForm
from_email = None
html_email_template_name = None
subject_template_name = "user/password_reset_subject.txt"
success_url = reverse_lazy("password_reset_done")
template_name = "user/password_reset_form.html"
title = ("Password reset")
token_generator = default_token_generator
@method_decorator(csrf_protect)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
def form_valid(self, form):
opts = {
"use_https": self.request.is_secure(),
"token_generator": self.token_generator,
"from_email": self.from_email,
"email_template_name": self.email_template_name,
"subject_template_name": self.subject_template_name,
"request": self.request,
"html_email_template_name": self.html_email_template_name,
"extra_email_context": self.extra_email_context,
}
form.save(**opts)
return super().form_valid(form)
and I created this file user/password_reset_subject.txt
MyAPP- Registration/Login App Password Reset
then I changed the password_reset_email.html
{{ protocol }}://10.6.45.152{% url 'password_reset_confirm' uidb64=uid token=token %}