Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- project setting.py,,,,,,
- # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- # Quick-start development settings - unsuitable for production
- # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
- # SECURITY WARNING: keep the secret key used in production secret!
- SECRET_KEY = '@5-1_k=%_8xh@xc(_m^1y@8a*g85=9$-pu1ei^#7u87%6l4_sz'
- # SECURITY WARNING: don't run with debug turned on in production!
- DEBUG = True
- ALLOWED_HOSTS = []
- # Application definition
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'blog.apps.BlogConfig',
- ]
- MIDDLEWARE = [
- 'django.middleware.security.SecurityMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.common.CommonMiddleware',
- 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
- ]
- ROOT_URLCONF = 'mysite.urls'
- TEMPLATES = [
- {
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'DIRS': [os.path.join(BASE_DIR, 'templates')]
- ,
- 'APP_DIRS': True,
- 'OPTIONS': {
- 'context_processors': [
- 'django.template.context_processors.debug',
- 'django.template.context_processors.request',
- 'django.contrib.auth.context_processors.auth',
- 'django.contrib.messages.context_processors.messages',
- ],
- },
- },
- ]
- WSGI_APPLICATION = 'mysite.wsgi.application'
- EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
- EMAIL_USE_TLS = True
- EMAIL_HOST = 'smtp.gmail.com'
- EMAIL_HOST_USER = 'youremail@gmail.com'
- EMAIL_HOST_PASSWORD = 'yourpassword'
- EMAIL_PORT = 587
- # EMAIL_HOST = 'smtp.sendgrid.net'
- # EMAIL_HOST_USER = 'sendgrid_username'
- # EMAIL_HOST_PASSWORD = 'sendgrid_password'
- # EMAIL_PORT = 587
- # EMAIL_USE_TLS = True
- # Database
- # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
- }
- }
- # Password validation
- # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
- AUTH_PASSWORD_VALIDATORS = [
- {
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
- },
- ]
- # Internationalization
- # https://docs.djangoproject.com/en/1.11/topics/i18n/
- LANGUAGE_CODE = 'en-us'
- TIME_ZONE = 'UTC'
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- # Static files (CSS, JavaScript, Images)
- # https://docs.djangoproject.com/en/1.11/howto/static-files/
- STATIC_URL = '/static/'
- app view.py code................given that,
- from django.http import HttpResponse
- from django.shortcuts import render, redirect
- from django.contrib.auth import login, authenticate
- from .forms import SignupForm
- from django.contrib.sites.shortcuts import get_current_site
- from django.utils.encoding import force_bytes, force_text
- from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
- from django.template.loader import render_to_string
- from .tokens import account_activation_token
- from django.contrib.auth.models import User
- from django.core.mail import EmailMessage
- def home(request):
- return render(request, 'home.html')
- def signup(request):
- if request.method == 'POST':
- form = SignupForm(request.POST)
- if form.is_valid():
- user = form.save(commit=False)
- user.is_active = False
- user.save()
- current_site = get_current_site(request)
- message = render_to_string('acc_active_email.html', {
- 'user':user, 'domain':current_site.domain,
- 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
- 'token': account_activation_token.make_token(user),
- })
- # Sending activation link in terminal
- #user.email_user(subject, message)
- mail_subject = 'Activate your service account.'
- to_email = form.cleaned_data.get('email')
- email = EmailMessage(mail_subject, message, to=[to_email])
- email.send()
- return HttpResponse('Please confirm your email address to complete the registration.')
- #return render(request, 'acc_active_sent.html')
- else:
- form = SignupForm()
- return render(request, 'signup.html', {'form': form})
- def activate(request, uidb64, token):
- try:
- uid = force_text(urlsafe_base64_decode(uidb64))
- user = User.objects.get(pk=uid)
- except(TypeError, ValueError, OverflowError, User.DoesNotExist):
- user = None
- if user is not None and account_activation_token.check_token(user, token):
- user.is_active = True
- user.save()
- login(request, user)
- return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
- else:
- return HttpResponse('Activation link is invalid!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement