Advertisement
Yeasincse

কোড রান হয় কিন্তু মেইল send হয় না . ইমেইল ভেরিফিকেশন করে si

Dec 30th, 2017
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.63 KB | None | 0 0
  1. project setting.py,,,,,,
  2.  
  3. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  4. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  5.  
  6.  
  7. # Quick-start development settings - unsuitable for production
  8. # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
  9.  
  10. # SECURITY WARNING: keep the secret key used in production secret!
  11. SECRET_KEY = '@5-1_k=%_8xh@xc(_m^1y@8a*g85=9$-pu1ei^#7u87%6l4_sz'
  12.  
  13. # SECURITY WARNING: don't run with debug turned on in production!
  14. DEBUG = True
  15.  
  16. ALLOWED_HOSTS = []
  17.  
  18.  
  19. # Application definition
  20.  
  21. INSTALLED_APPS = [
  22.     'django.contrib.admin',
  23.     'django.contrib.auth',
  24.     'django.contrib.contenttypes',
  25.     'django.contrib.sessions',
  26.     'django.contrib.messages',
  27.     'django.contrib.staticfiles',
  28.     'blog.apps.BlogConfig',
  29. ]
  30.  
  31. MIDDLEWARE = [
  32.     'django.middleware.security.SecurityMiddleware',
  33.     'django.contrib.sessions.middleware.SessionMiddleware',
  34.     'django.middleware.common.CommonMiddleware',
  35.     'django.middleware.csrf.CsrfViewMiddleware',
  36.     'django.contrib.auth.middleware.AuthenticationMiddleware',
  37.     'django.contrib.messages.middleware.MessageMiddleware',
  38.     'django.middleware.clickjacking.XFrameOptionsMiddleware',
  39. ]
  40.  
  41. ROOT_URLCONF = 'mysite.urls'
  42.  
  43. TEMPLATES = [
  44.     {
  45.         'BACKEND': 'django.template.backends.django.DjangoTemplates',
  46.         'DIRS': [os.path.join(BASE_DIR, 'templates')]
  47.         ,
  48.         'APP_DIRS': True,
  49.         'OPTIONS': {
  50.             'context_processors': [
  51.                 'django.template.context_processors.debug',
  52.                 'django.template.context_processors.request',
  53.                 'django.contrib.auth.context_processors.auth',
  54.                 'django.contrib.messages.context_processors.messages',
  55.             ],
  56.         },
  57.     },
  58. ]
  59.  
  60. WSGI_APPLICATION = 'mysite.wsgi.application'
  61.  
  62. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  63. EMAIL_USE_TLS = True
  64. EMAIL_HOST = 'smtp.gmail.com'
  65. EMAIL_HOST_USER = 'youremail@gmail.com'
  66. EMAIL_HOST_PASSWORD = 'yourpassword'
  67. EMAIL_PORT = 587
  68.  
  69. # EMAIL_HOST = 'smtp.sendgrid.net'
  70. # EMAIL_HOST_USER = 'sendgrid_username'
  71. # EMAIL_HOST_PASSWORD = 'sendgrid_password'
  72. # EMAIL_PORT = 587
  73. # EMAIL_USE_TLS = True
  74.  
  75. # Database
  76. # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
  77.  
  78. DATABASES = {
  79.     'default': {
  80.         'ENGINE': 'django.db.backends.sqlite3',
  81.         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  82.     }
  83. }
  84.  
  85.  
  86. # Password validation
  87. # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
  88.  
  89. AUTH_PASSWORD_VALIDATORS = [
  90.     {
  91.         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  92.     },
  93.     {
  94.         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  95.     },
  96.     {
  97.         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  98.     },
  99.     {
  100.         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  101.     },
  102. ]
  103.  
  104.  
  105. # Internationalization
  106. # https://docs.djangoproject.com/en/1.11/topics/i18n/
  107.  
  108. LANGUAGE_CODE = 'en-us'
  109.  
  110. TIME_ZONE = 'UTC'
  111.  
  112. USE_I18N = True
  113.  
  114. USE_L10N = True
  115.  
  116. USE_TZ = True
  117.  
  118.  
  119. # Static files (CSS, JavaScript, Images)
  120. # https://docs.djangoproject.com/en/1.11/howto/static-files/
  121.  
  122. STATIC_URL = '/static/'
  123.  
  124.  
  125.  
  126. app view.py code................given that,
  127.  
  128. from django.http import HttpResponse
  129. from django.shortcuts import render, redirect
  130. from django.contrib.auth import login, authenticate
  131. from .forms import SignupForm
  132. from django.contrib.sites.shortcuts import get_current_site
  133. from django.utils.encoding import force_bytes, force_text
  134. from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
  135. from django.template.loader import render_to_string
  136. from .tokens import account_activation_token
  137. from django.contrib.auth.models import User
  138. from django.core.mail import EmailMessage
  139.  
  140.  
  141. def home(request):
  142.     return render(request, 'home.html')
  143.  
  144.  
  145. def signup(request):
  146.     if request.method == 'POST':
  147.         form = SignupForm(request.POST)
  148.         if form.is_valid():
  149.             user = form.save(commit=False)
  150.             user.is_active = False
  151.             user.save()
  152.             current_site = get_current_site(request)
  153.             message = render_to_string('acc_active_email.html', {
  154.                 'user':user, 'domain':current_site.domain,
  155.                 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
  156.                 'token': account_activation_token.make_token(user),
  157.             })
  158.             # Sending activation link in terminal
  159.             #user.email_user(subject, message)
  160.             mail_subject = 'Activate your service account.'
  161.             to_email = form.cleaned_data.get('email')
  162.             email = EmailMessage(mail_subject, message, to=[to_email])
  163.             email.send()
  164.             return HttpResponse('Please confirm your email address to complete the registration.')
  165.             #return render(request, 'acc_active_sent.html')
  166.     else:
  167.         form = SignupForm()
  168.     return render(request, 'signup.html', {'form': form})
  169.  
  170.  
  171. def activate(request, uidb64, token):
  172.     try:
  173.         uid = force_text(urlsafe_base64_decode(uidb64))
  174.         user = User.objects.get(pk=uid)
  175.     except(TypeError, ValueError, OverflowError, User.DoesNotExist):
  176.         user = None
  177.     if user is not None and account_activation_token.check_token(user, token):
  178.         user.is_active = True
  179.         user.save()
  180.         login(request, user)
  181.         return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
  182.     else:
  183.         return HttpResponse('Activation link is invalid!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement