Re: REG: Why my django email settings not sending email notifications?

2019-02-17 Thread Onkar Narkar

Hi Amitesh,

 Are you getting some error like this:
smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific 
password required. Learn more at\n5.7.9  
https://support.google.com/mail/?p=InvalidSecondFactor 128sm18480521pfx.7 - 
gsmtp')

If this is the case, you need to specify *application* *specific password* 
instead of your nornal in gmail password.

On Sunday, 17 February 2019 14:49:35 UTC+5:30, Amitesh Sahay wrote:
>
> I have created a registration page that sends an email notification on 
> successful registration. I do have my email notification in place. But it 
> doesn't seem to be working, neither it is throwing any error. Below is the 
> code snippet.
> views.py
>
> def register(request):
> validators = [MinimumLengthValidator, NumberValidator, UppercaseValidator]
> if request.method == 'POST':
> first_name = request.POST['first_name']
> last_name = request.POST['last_name']
> email = request.POST['email']
> username = request.POST['username']
> password = request.POST['password']
> try:
> for validator in validators:
> validator().validate(password)
> except ValueError as e:
> messages.error(request, str(e))
> return redirect('register')
> password2 = request.POST['password2']
>
> # check if the password match
> if password == password2:
>
> if User.objects.filter(username=username).exists():
> messages.error(request, 'username already exist')
> return redirect('register')
> else:
> if User.objects.filter(email=email).exists():
> messages.error(request, 'Registration Failed - Try 
> different email address')
> return redirect('register')
> else:
> user = User.objects.create_user(username=username, 
> password=password, email=email,
> first_name=first_name, 
> last_name=last_name)
> user.save()
> messages.success(request, 'Registration complete, please 
> proceed to login')
> return redirect('register')
> else:
> messages.error(request, 'password dose not match')
> return redirect('register')
> else:
> return render(request, 'ACCOUNTS/register.html')
>
> def ThankYou(request, register):
> if request.method == 'POST':
> if register.is_valid():
> save_it = register.save(commit=False)
> save_it.save()
> subject = 'Registration successful'
> message = 'Thank you for registration, please continue with 
> the login'
> from_email = settings.EMAIL_HOST_USER
> to_list = [save_it.email, settings.EMAIL_HOST_USER]
> try:
> send_mail(
> subject,
> message,
> from_email,
> [to_list],
> fail_silently=False,
> )
> except ValueError:
> return HttpResponse('Invalid header found.')
> else:
> messages.success(request, 'thank you ')
> return redirect('register')
> else:
> return redirect('index')
>
> Below is my settings.py
>
> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
> EMAIL_USE_TLS = False
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_PORT = 587
> EMAIL_HOST_USER = 'ami@gmail.com '
> EMAIL_HOST_PASSWORD = '123'
> DEFAULT_FROM_EMAIL = 'ami@gmail.com '
>
> I have gone through a couple of Stackoverflow posts and made some changes 
> as suggested. But they do not seem to have any effect. Below is one of the 
> link.
>
> Django Doesn't Send Email Notifications 
> 
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bfc6ce59-182a-421f-826c-2e322d4b20a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Working with pk arguments within an included URL

2019-02-17 Thread Gavin Boyle
Hi Simon,

That’s a great idea, I’ve only ever worked with built in sessions for
logging in. Would you have a link to some documentation or an example that
would help me as I’m relatively new to Django and this has been holding me
back months now.

Thanks

Gavin

On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:

> I think I had a similar scenario a few weeks ago. One option that you have
> is to store the originally selected PK to the session object. Whenever you
> load a page, for you can retrieve the PK from the session object. Most
> likely you'll do this on the get_queryset function
>
>
> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>>
>> Hi,
>>
>> To briefly explained:
>>
>>- I have a main site which provides links to multiple sports club
>>pages.
>>- Currently once clicked it opens the club home page and displays
>>information based on that club by passing in the pk.
>>- I then have many other pages associated to the clubs. e.g. Teams,
>>Player Registration, Shop etc.
>>- But when I click on the navbar for example "Player Registration" I
>>have no idea how to continue the URL with the originally selected PK and
>>how to use that PK in the view.
>>
>>
>> ***Current I have these pages working off the authenticated user but
>> realistically I want it working off the originally selected club***
>>
>> I am not sure how to write the view to allow for this to work and then
>> pass the pk argument into the nav bar url simiarlary how I did it on the
>> main site:
>>
>> 
>>
>>
>> Would really appreciate any help been stuck on this for a few months now.
>>
>> Below is an example of the Clubs Teams I need this to work for:
>>
>> *Urls.py:*
>>
>> urlpatterns = [
>> path('', views.club_home, name='club_home'),
>> path('/', include([
>> path('home/', views.club_home, name='club_home_with_pk'),
>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>> ])),
>>
>>
>> *Nav bar for club pages:*
>>
>> Home
>> Team
>> Pitches
>> Memberships
>>
>>
>>
>> *Views.py*
>>
>>
>> def club_home(request, pk=None):
>> if pk:
>> club = ClubInfo.objects.filter(pk=pk)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> elif request.user.is_authenticated:
>> club = ClubInfo.objects.filter(user=request.user)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> # photo = model.club_logo.ImageField(storage=profile_pics)
>> args = {'club': club,
>> 'club_posts': club_posts
>> }
>> return render(request, 'club_home_page.html', args)
>>
>>
>> class TeamInfo(APIView):
>> renderer_classes = [TemplateHTMLRenderer]
>> template_name = 'teams.html'
>>
>> def get(self, request):
>> form = TeamForm()
>> user = ClubInfo.objects.filter(user=request.user).first()
>> teams = Team.objects.filter(club_id=user.pk)
>> return Response({'form': form,
>>  'teams': teams,
>>  })
>>
>> def post(self, request):
>> form = TeamForm(data=request.data)
>> user = ClubInfo.objects.filter(user=request.user).first()
>> teams = Team.objects.filter(club_id=user.pk)
>> if form.is_valid():
>> form.save()
>> return Response({'form': form,
>>  'teams': teams
>>  })
>>
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/KsvZHK1z6BI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: REG: Why my django email settings not sending email notifications?

2019-02-17 Thread Siddharth Tamang
When I used gmail for my testing, I had to go to my gmail settings to turn
on some settings. Sorry cannot remember it but I will try to find what it
was. By the way what does the debug error says?

On Mon, Feb 18, 2019 at 9:42 AM Simon A  wrote:

> Just to add, please try to create a python file with the simplest
> implementation of send mail just to check if it actually works.
>
> On Monday, February 18, 2019 at 11:43:22 AM UTC+8, Sid wrote:
>>
>> can you check if you your email server is somehow blocking your emails?
>> Have you enabled your debug settings ON?
>>
>> On Sun, Feb 17, 2019 at 2:49 PM 'Amitesh Sahay' via Django users <
>> django...@googlegroups.com> wrote:
>>
>>> I have created a registration page that sends an email notification on
>>> successful registration. I do have my email notification in place. But it
>>> doesn't seem to be working, neither it is throwing any error. Below is the
>>> code snippet.
>>> views.py
>>>
>>> def register(request):
>>> validators = [MinimumLengthValidator, NumberValidator, 
>>> UppercaseValidator]
>>> if request.method == 'POST':
>>> first_name = request.POST['first_name']
>>> last_name = request.POST['last_name']
>>> email = request.POST['email']
>>> username = request.POST['username']
>>> password = request.POST['password']
>>> try:
>>> for validator in validators:
>>> validator().validate(password)
>>> except ValueError as e:
>>> messages.error(request, str(e))
>>> return redirect('register')
>>> password2 = request.POST['password2']
>>>
>>> # check if the password match
>>> if password == password2:
>>>
>>> if User.objects.filter(username=username).exists():
>>> messages.error(request, 'username already exist')
>>> return redirect('register')
>>> else:
>>> if User.objects.filter(email=email).exists():
>>> messages.error(request, 'Registration Failed - Try 
>>> different email address')
>>> return redirect('register')
>>> else:
>>> user = User.objects.create_user(username=username, 
>>> password=password, email=email,
>>> first_name=first_name, 
>>> last_name=last_name)
>>> user.save()
>>> messages.success(request, 'Registration complete, 
>>> please proceed to login')
>>> return redirect('register')
>>> else:
>>> messages.error(request, 'password dose not match')
>>> return redirect('register')
>>> else:
>>> return render(request, 'ACCOUNTS/register.html')
>>>
>>> def ThankYou(request, register):
>>> if request.method == 'POST':
>>> if register.is_valid():
>>> save_it = register.save(commit=False)
>>> save_it.save()
>>> subject = 'Registration successful'
>>> message = 'Thank you for registration, please continue with 
>>> the login'
>>> from_email = settings.EMAIL_HOST_USER
>>> to_list = [save_it.email, settings.EMAIL_HOST_USER]
>>> try:
>>> send_mail(
>>> subject,
>>> message,
>>> from_email,
>>> [to_list],
>>> fail_silently=False,
>>> )
>>> except ValueError:
>>> return HttpResponse('Invalid header found.')
>>> else:
>>> messages.success(request, 'thank you ')
>>> return redirect('register')
>>> else:
>>> return redirect('index')
>>>
>>> Below is my settings.py
>>>
>>> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>>> EMAIL_USE_TLS = False
>>> EMAIL_HOST = 'smtp.gmail.com'
>>> EMAIL_PORT = 587
>>> EMAIL_HOST_USER = 'ami@gmail.com'
>>> EMAIL_HOST_PASSWORD = '123'
>>> DEFAULT_FROM_EMAIL = 'ami@gmail.com'
>>>
>>> I have gone through a couple of Stackoverflow posts and made some
>>> changes as suggested. But they do not seem to have any effect. Below is one
>>> of the link.
>>>
>>> Django Doesn't Send Email Notifications
>>> 
>>> Regards,
>>> Amitesh Sahay
>>> *91-750 797 8619*
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> 

Re: REG: Why my django email settings not sending email notifications?

2019-02-17 Thread Simon A
Just to add, please try to create a python file with the simplest 
implementation of send mail just to check if it actually works. 

On Monday, February 18, 2019 at 11:43:22 AM UTC+8, Sid wrote:
>
> can you check if you your email server is somehow blocking your emails? 
> Have you enabled your debug settings ON?
>
> On Sun, Feb 17, 2019 at 2:49 PM 'Amitesh Sahay' via Django users <
> django...@googlegroups.com > wrote:
>
>> I have created a registration page that sends an email notification on 
>> successful registration. I do have my email notification in place. But it 
>> doesn't seem to be working, neither it is throwing any error. Below is the 
>> code snippet.
>> views.py
>>
>> def register(request):
>> validators = [MinimumLengthValidator, NumberValidator, 
>> UppercaseValidator]
>> if request.method == 'POST':
>> first_name = request.POST['first_name']
>> last_name = request.POST['last_name']
>> email = request.POST['email']
>> username = request.POST['username']
>> password = request.POST['password']
>> try:
>> for validator in validators:
>> validator().validate(password)
>> except ValueError as e:
>> messages.error(request, str(e))
>> return redirect('register')
>> password2 = request.POST['password2']
>>
>> # check if the password match
>> if password == password2:
>>
>> if User.objects.filter(username=username).exists():
>> messages.error(request, 'username already exist')
>> return redirect('register')
>> else:
>> if User.objects.filter(email=email).exists():
>> messages.error(request, 'Registration Failed - Try 
>> different email address')
>> return redirect('register')
>> else:
>> user = User.objects.create_user(username=username, 
>> password=password, email=email,
>> first_name=first_name, 
>> last_name=last_name)
>> user.save()
>> messages.success(request, 'Registration complete, please 
>> proceed to login')
>> return redirect('register')
>> else:
>> messages.error(request, 'password dose not match')
>> return redirect('register')
>> else:
>> return render(request, 'ACCOUNTS/register.html')
>>
>> def ThankYou(request, register):
>> if request.method == 'POST':
>> if register.is_valid():
>> save_it = register.save(commit=False)
>> save_it.save()
>> subject = 'Registration successful'
>> message = 'Thank you for registration, please continue with 
>> the login'
>> from_email = settings.EMAIL_HOST_USER
>> to_list = [save_it.email, settings.EMAIL_HOST_USER]
>> try:
>> send_mail(
>> subject,
>> message,
>> from_email,
>> [to_list],
>> fail_silently=False,
>> )
>> except ValueError:
>> return HttpResponse('Invalid header found.')
>> else:
>> messages.success(request, 'thank you ')
>> return redirect('register')
>> else:
>> return redirect('index')
>>
>> Below is my settings.py
>>
>> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>> EMAIL_USE_TLS = False
>> EMAIL_HOST = 'smtp.gmail.com'
>> EMAIL_PORT = 587
>> EMAIL_HOST_USER = 'ami@gmail.com '
>> EMAIL_HOST_PASSWORD = '123'
>> DEFAULT_FROM_EMAIL = 'ami@gmail.com '
>>
>> I have gone through a couple of Stackoverflow posts and made some changes 
>> as suggested. But they do not seem to have any effect. Below is one of the 
>> link.
>>
>> Django Doesn't Send Email Notifications 
>> 
>> Regards,
>> Amitesh Sahay
>> *91-750 797 8619*
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1493971974.505339.1550394996512%40mail.yahoo.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Thank you
> Siddharth Tamang
> AWS Certified Solutions Architect - Associate
>

-- 

Re: Working with pk arguments within an included URL

2019-02-17 Thread Simon A
I think I had a similar scenario a few weeks ago. One option that you have 
is to store the originally selected PK to the session object. Whenever you 
load a page, for you can retrieve the PK from the session object. Most 
likely you'll do this on the get_queryset function

On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>
> Hi,
>
> To briefly explained:
>
>- I have a main site which provides links to multiple sports club 
>pages.
>- Currently once clicked it opens the club home page and displays 
>information based on that club by passing in the pk.
>- I then have many other pages associated to the clubs. e.g. Teams, 
>Player Registration, Shop etc.
>- But when I click on the navbar for example "Player Registration" I 
>have no idea how to continue the URL with the originally selected PK and 
>how to use that PK in the view.
>
>
> ***Current I have these pages working off the authenticated user but 
> realistically I want it working off the originally selected club***
>
> I am not sure how to write the view to allow for this to work and then 
> pass the pk argument into the nav bar url simiarlary how I did it on the 
> main site:
>
> 
>
>
> Would really appreciate any help been stuck on this for a few months now. 
>
> Below is an example of the Clubs Teams I need this to work for:
>
> *Urls.py:*
>
> urlpatterns = [
> path('', views.club_home, name='club_home'),
> path('/', include([
> path('home/', views.club_home, name='club_home_with_pk'),
> path('teams/', views.TeamInfo.as_view(), name='teams'),
> ])),
>
>
> *Nav bar for club pages:*
>
> Home
> Team
> Pitches
> Memberships
>
>
>
> *Views.py*
>
>
> def club_home(request, pk=None):
> if pk:
> club = ClubInfo.objects.filter(pk=pk)
> club_posts = ClubPosts.objects.filter(club_id=club[0])
> elif request.user.is_authenticated:
> club = ClubInfo.objects.filter(user=request.user)
> club_posts = ClubPosts.objects.filter(club_id=club[0])
> # photo = model.club_logo.ImageField(storage=profile_pics)
> args = {'club': club,
> 'club_posts': club_posts
> }
> return render(request, 'club_home_page.html', args)
>
>
> class TeamInfo(APIView):
> renderer_classes = [TemplateHTMLRenderer]
> template_name = 'teams.html'
>
> def get(self, request):
> form = TeamForm()
> user = ClubInfo.objects.filter(user=request.user).first()
> teams = Team.objects.filter(club_id=user.pk)
> return Response({'form': form,
>  'teams': teams,
>  })
>
> def post(self, request):
> form = TeamForm(data=request.data)
> user = ClubInfo.objects.filter(user=request.user).first()
> teams = Team.objects.filter(club_id=user.pk)
> if form.is_valid():
> form.save()
> return Response({'form': form,
>  'teams': teams
>  })
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: REG: Why my django email settings not sending email notifications?

2019-02-17 Thread 'Amitesh Sahay' via Django users
The email server is a gmail smtp server. People across the globe use that for 
their development purpose. So, I guess that shouldn't be a issue. The debug is 
"ON" by default.


Regards,
Amitesh Sahay91-750 797 8619 

   On Monday, 18 February, 2019, 9:12:57 am IST, Siddharth Tamang 
 wrote: 
 
 can you check if you your email server is somehow blocking your emails? Have 
you enabled your debug settings ON?
On Sun, Feb 17, 2019 at 2:49 PM 'Amitesh Sahay' via Django users 
 wrote:

I have created a registration page that sends an email notification on 
successful registration. I do have my email notification in place. But it 
doesn't seem to be working, neither it is throwing any error. Below is the code 
snippet.

views.py
def register(request):
validators = [MinimumLengthValidator, NumberValidator, UppercaseValidator]
if request.method == 'POST':
first_name = request.POST['first_name']
last_name = request.POST['last_name']
email = request.POST['email']
username = request.POST['username']
password = request.POST['password']
try:
for validator in validators:
validator().validate(password)
except ValueError as e:
messages.error(request, str(e))
return redirect('register')
password2 = request.POST['password2']

# check if the password match
if password == password2:

if User.objects.filter(username=username).exists():
messages.error(request, 'username already exist')
return redirect('register')
else:
if User.objects.filter(email=email).exists():
messages.error(request, 'Registration Failed - Try 
different email address')
return redirect('register')
else:
user = User.objects.create_user(username=username, 
password=password, email=email,
first_name=first_name, 
last_name=last_name)
user.save()
messages.success(request, 'Registration complete, please 
proceed to login')
return redirect('register')
else:
messages.error(request, 'password dose not match')
return redirect('register')
else:
return render(request, 'ACCOUNTS/register.html')


def ThankYou(request, register):
if request.method == 'POST':
if register.is_valid():
save_it = register.save(commit=False)
save_it.save()
subject = 'Registration successful'
message = 'Thank you for registration, please continue with the 
login'
from_email = settings.EMAIL_HOST_USER
to_list = [save_it.email, settings.EMAIL_HOST_USER]
try:
send_mail(
subject,
message,
from_email,
[to_list],
fail_silently=False,
)
except ValueError:
return HttpResponse('Invalid header found.')
else:
messages.success(request, 'thank you ')
return redirect('register')
else:
return redirect('index')
Below is my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'ami.sa...@gmail.com'
EMAIL_HOST_PASSWORD = '123'
DEFAULT_FROM_EMAIL = 'ami.sa...@gmail.com'
I have gone through a couple of Stackoverflow posts and made some changes as 
suggested. But they do not seem to have any effect. Below is one of the link.

Django Doesn't Send Email Notifications
Regards,
Amitesh Sahay91-750 797 8619

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1493971974.505339.1550394996512%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.



-- 
Thank youSiddharth TamangAWS Certified Solutions Architect - Associate

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 

Re: REG: Why my django email settings not sending email notifications?

2019-02-17 Thread Siddharth Tamang
can you check if you your email server is somehow blocking your emails?
Have you enabled your debug settings ON?

On Sun, Feb 17, 2019 at 2:49 PM 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> I have created a registration page that sends an email notification on
> successful registration. I do have my email notification in place. But it
> doesn't seem to be working, neither it is throwing any error. Below is the
> code snippet.
> views.py
>
> def register(request):
> validators = [MinimumLengthValidator, NumberValidator, UppercaseValidator]
> if request.method == 'POST':
> first_name = request.POST['first_name']
> last_name = request.POST['last_name']
> email = request.POST['email']
> username = request.POST['username']
> password = request.POST['password']
> try:
> for validator in validators:
> validator().validate(password)
> except ValueError as e:
> messages.error(request, str(e))
> return redirect('register')
> password2 = request.POST['password2']
>
> # check if the password match
> if password == password2:
>
> if User.objects.filter(username=username).exists():
> messages.error(request, 'username already exist')
> return redirect('register')
> else:
> if User.objects.filter(email=email).exists():
> messages.error(request, 'Registration Failed - Try 
> different email address')
> return redirect('register')
> else:
> user = User.objects.create_user(username=username, 
> password=password, email=email,
> first_name=first_name, 
> last_name=last_name)
> user.save()
> messages.success(request, 'Registration complete, please 
> proceed to login')
> return redirect('register')
> else:
> messages.error(request, 'password dose not match')
> return redirect('register')
> else:
> return render(request, 'ACCOUNTS/register.html')
>
> def ThankYou(request, register):
> if request.method == 'POST':
> if register.is_valid():
> save_it = register.save(commit=False)
> save_it.save()
> subject = 'Registration successful'
> message = 'Thank you for registration, please continue with 
> the login'
> from_email = settings.EMAIL_HOST_USER
> to_list = [save_it.email, settings.EMAIL_HOST_USER]
> try:
> send_mail(
> subject,
> message,
> from_email,
> [to_list],
> fail_silently=False,
> )
> except ValueError:
> return HttpResponse('Invalid header found.')
> else:
> messages.success(request, 'thank you ')
> return redirect('register')
> else:
> return redirect('index')
>
> Below is my settings.py
>
> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
> EMAIL_USE_TLS = False
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_PORT = 587
> EMAIL_HOST_USER = 'ami.sa...@gmail.com'
> EMAIL_HOST_PASSWORD = '123'
> DEFAULT_FROM_EMAIL = 'ami.sa...@gmail.com'
>
> I have gone through a couple of Stackoverflow posts and made some changes
> as suggested. But they do not seem to have any effect. Below is one of the
> link.
>
> Django Doesn't Send Email Notifications
> 
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1493971974.505339.1550394996512%40mail.yahoo.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thank you
Siddharth Tamang
AWS Certified Solutions Architect - Associate

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at 

Why use CustomUserManager.create_user and not CustomUserManager.create?

2019-02-17 Thread Maarten Nieber
Hi,

the Django guidelines tell us to implement CustomUserManager.create_user. 
However, this seems to introduce some ambiguity between
CustomUserManager.create_user and CustomUserManager.create, since both 
these methods can be expected to create a User. In fact,
it would be easy to accidentically call the wrong method from source code.

Is there any reason why the create_user function exists at all? Why doesn't 
Django tell us to override CustomUserManager.create?

Or alternatively, I could imagine that Django could have a hook function 
that is called by CustomUserManager.create, where the hook can be used
to implemented custom behaviour (so that at least we have only 1 function 
to create users). Would this be a better design? Or is the current
design the correct one, and am I missing something? (in that case, please 
elaborate)

Best regards,
Maarten


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b934b1a4-a295-4e83-be9c-b787785e5fc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Working with pk arguments within an included URL

2019-02-17 Thread GavinB841
Hi,

To briefly explained:

   - I have a main site which provides links to multiple sports club pages.
   - Currently once clicked it opens the club home page and displays 
   information based on that club by passing in the pk.
   - I then have many other pages associated to the clubs. e.g. Teams, 
   Player Registration, Shop etc.
   - But when I click on the navbar for example "Player Registration" I 
   have no idea how to continue the URL with the originally selected PK and 
   how to use that PK in the view.


***Current I have these pages working off the authenticated user but 
realistically I want it working off the originally selected club***

I am not sure how to write the view to allow for this to work and then pass 
the pk argument into the nav bar url simiarlary how I did it on the main 
site:




Would really appreciate any help been stuck on this for a few months now. 

Below is an example of the Clubs Teams I need this to work for:

*Urls.py:*

urlpatterns = [
path('', views.club_home, name='club_home'),
path('/', include([
path('home/', views.club_home, name='club_home_with_pk'),
path('teams/', views.TeamInfo.as_view(), name='teams'),
])),


*Nav bar for club pages:*

Home
Team
Pitches
Memberships



*Views.py*


def club_home(request, pk=None):
if pk:
club = ClubInfo.objects.filter(pk=pk)
club_posts = ClubPosts.objects.filter(club_id=club[0])
elif request.user.is_authenticated:
club = ClubInfo.objects.filter(user=request.user)
club_posts = ClubPosts.objects.filter(club_id=club[0])
# photo = model.club_logo.ImageField(storage=profile_pics)
args = {'club': club,
'club_posts': club_posts
}
return render(request, 'club_home_page.html', args)


class TeamInfo(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'teams.html'

def get(self, request):
form = TeamForm()
user = ClubInfo.objects.filter(user=request.user).first()
teams = Team.objects.filter(club_id=user.pk)
return Response({'form': form,
 'teams': teams,
 })

def post(self, request):
form = TeamForm(data=request.data)
user = ClubInfo.objects.filter(user=request.user).first()
teams = Team.objects.filter(club_id=user.pk)
if form.is_valid():
form.save()
return Response({'form': form,
 'teams': teams
 })




-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/342241f0-cbf9-4a38-b980-139a79d1d7e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


REG: Why my django email settings not sending email notifications?

2019-02-17 Thread 'Amitesh Sahay' via Django users
I have created a registration page that sends an email notification on 
successful registration. I do have my email notification in place. But it 
doesn't seem to be working, neither it is throwing any error. Below is the code 
snippet.

views.py
def register(request):
validators = [MinimumLengthValidator, NumberValidator, UppercaseValidator]
if request.method == 'POST':
first_name = request.POST['first_name']
last_name = request.POST['last_name']
email = request.POST['email']
username = request.POST['username']
password = request.POST['password']
try:
for validator in validators:
validator().validate(password)
except ValueError as e:
messages.error(request, str(e))
return redirect('register')
password2 = request.POST['password2']

# check if the password match
if password == password2:

if User.objects.filter(username=username).exists():
messages.error(request, 'username already exist')
return redirect('register')
else:
if User.objects.filter(email=email).exists():
messages.error(request, 'Registration Failed - Try 
different email address')
return redirect('register')
else:
user = User.objects.create_user(username=username, 
password=password, email=email,
first_name=first_name, 
last_name=last_name)
user.save()
messages.success(request, 'Registration complete, please 
proceed to login')
return redirect('register')
else:
messages.error(request, 'password dose not match')
return redirect('register')
else:
return render(request, 'ACCOUNTS/register.html')


def ThankYou(request, register):
if request.method == 'POST':
if register.is_valid():
save_it = register.save(commit=False)
save_it.save()
subject = 'Registration successful'
message = 'Thank you for registration, please continue with the 
login'
from_email = settings.EMAIL_HOST_USER
to_list = [save_it.email, settings.EMAIL_HOST_USER]
try:
send_mail(
subject,
message,
from_email,
[to_list],
fail_silently=False,
)
except ValueError:
return HttpResponse('Invalid header found.')
else:
messages.success(request, 'thank you ')
return redirect('register')
else:
return redirect('index')
Below is my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'ami.sa...@gmail.com'
EMAIL_HOST_PASSWORD = '123'
DEFAULT_FROM_EMAIL = 'ami.sa...@gmail.com'
I have gone through a couple of Stackoverflow posts and made some changes as 
suggested. But they do not seem to have any effect. Below is one of the link.

Django Doesn't Send Email Notifications
Regards,
Amitesh Sahay91-750 797 8619

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1493971974.505339.1550394996512%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.