您的位置:首页 > 编程语言 > Go语言

django配置django-registration-redux

2015-09-11 15:35 633 查看
1.需要环境pip install django-registration-redux ,我用的版本是1.3beta版本。下载下来的版本不能直接用,缺少base.html模板文件,可以直接用github上下载,地址:
https://github.com/macropin/django-registration,将test_app/templates/base.html拷贝到python的site-packages/registration的templates目录下。
2.搭配好环境之后使用django-admin.exe startproject register 新建一个django项目register,将test_app/templates/profile.html拷贝到register/register/templates目录下

3.修改register/register下的setting.py配置文件,配置文件如下:

"""
Django settings for register project.

Generated by 'django-admin startproject' using Django 1.8.4.

For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ 
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

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.8/howto/deployment/checklist/ 
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'mu9pjw6e63v(aqc)ndtt-as*&cdf#6rx*-7n+s6k9jko+nobc1'

# 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',

'registration',
#'registration_email',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'register.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'register.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases 
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/ 
LANGUAGE_CODE = 'zh-CN'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/ 
STATIC_URL = '/static/'

#django.registration
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_EMAIL_SUBJECT_PREFIX = '[Django Registration Test App]'
SEND_ACTIVATION_EMAIL = True
REGISTRATION_AUTO_LOGIN = False

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

DEFAULT_FROM_EMAIL = '******@sina.cn'
EMAIL_HOST_PASSWORD = '*****'
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL

'''
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_SSL_CERTFILE = None
EMAIL_SSL_KEYFILE = None
EMAIL_TIMEOUT = None
'''
# Host for sending email.
EMAIL_HOST = 'smtp.sina.com.cn'

# Port for sending email.
EMAIL_PORT = 25

#ACCOUNT_ACTIVATION_DAYS = 7
'''

AUTHENTICATION_BACKENDS = (
'registration_email.auth.EmailBackend',
)

LOGIN_REDIRECT_URL = '/'

REGISTRATION_EMAIL_ACTIVATE_SUCCESS_URL = \
lambda request, user: '/accounts/activate/complete/'

REGISTRATION_EMAIL_REGISTER_SUCCESS_URL = \
lambda request, user: '/accounts/register/complete/'
'''


修改urls.py文件,如下:

"""register URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ Examples:
Function views
1. Add an import:  from my_app import views
2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
1. Add an import:  from other_app.views import Home
2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import:  from blog import urls as blog_urls
2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import TemplateView

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^accounts/profile/',
TemplateView.as_view(template_name='profile.html'),
name='profile'),
]


执行命令同步模型数据库
python.exe manager.py syncdb

执行命令运行服务,默认的端口地址是8000

python.exe manager.py runserver

打开本地页面进行测试

打开http://localhost:8000/accounts/register/注册

打开http://localhost:8000/accounts/login/登陆

打开http://localhost:8000/admin/进行账户管理
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: