django 1.10.3 userena 使用


参考  http://docs.django-userena.org/en/latest/installation.html#required-settings

http://wzgdavid.iteye.com/blog/2310816

 1、

import django

django.VERSION

发现django 版本为1.10.3

2、

运行python manage.py startapp accounts,出现问题cannot import name patterns

3、

根据提示,打开site-packages\guardian\compat

删掉from django.conf.urls import url, patterns, include, handler404, handler500中的 patterns

4、

再运行python manage.py startapp accounts,问题解决。

5、

python manage.py check_permissions 前运行 migrate 和 makemigrations
遇到account_myprofile doesn't exist时,把model中的class名MyProfile,改为小写,重新运行 migrate 和 makemigrations

6、

如果遇到可以注册,但是提交完就server error 500,

将port 改为465 或587

7、

server error 500的错误原因很多,记得设置debug=True


参考文:

我用的是django1.9.7, userena2.0.1

原来文档的顺序跑不出来, 我跑出来的顺序是

1  

 pip install django-userena

 

2  

Required settings

You need to make some changes Django settings if you want to use Userena in your project. This means modifying AUTHENTICATION_BACKENDSINSTALLED_APPS and optionally MIDDLEWARE_CLASSES.

Begin by adding , guardian and easy_thumbnails to the INSTALLED_APPS in your settings.py file of your project. django.contrib.sites must also be present if it is not already (see Django docs.).

Next add UserenaAuthenticationBackend and ObjectPermissionBackend also in your settings.py file, from django-guardian, at the top of AUTHENTICATION_BACKENDS. If you only have Django’s default backend, adding django-guardian and that of userena will get the following:

AUTHENTICATION_BACKENDS = (
    'userena.backends.UserenaAuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
    'django.contrib.auth.backends.ModelBackend',
)

add the following into your settings.py file:

ANONYMOUS_USER_ID = -1

 

3

Start New App

Next, you need to create a new app on your Django project. In your Command Prompt shell, type:python manage.py startapp accounts. We are creating a new app for Userena titled ‘accounts’.

Next, add accounts  userena to the INSTALLED_APPS in your settings.py file.

 

4

AUTH_PROFILE_MODULE = 'accounts.MyProfile'

To integrate Django with userena you should alter the following three settings to reflect the URI you have chosen for userena. For example, if userena lives under accounts:

USERENA_SIGNIN_REDIRECT_URL = '/accounts/%(username)s/'
LOGIN_URL = '/accounts/signin/'
LOGOUT_URL = '/accounts/signout/'

在accounts.models中加入

Python代码   收藏代码
  1. from __future__ import unicode_literals  
  2.   
  3. from django.db import models  
  4.   
  5. from django.contrib.auth.models import User  
  6. from django.utils.translation import ugettext as _  
  7. from userena.models import UserenaBaseProfile  
  8.   
  9. class MyProfile(UserenaBaseProfile):  
  10.     user = models.OneToOneField(User,  
  11.                                 unique=True,  
  12.                                 verbose_name=_('user'),  
  13.                                 related_name='my_profile')  
  14.     favourite_snack = models.CharField(_('favourite snack'),  
  15.                                        max_length=5)  

 

  6 接着url配置

在urls.py中加入

Python代码   收藏代码
  1. url(r'^accounts/', include('userena.urls')),  

 

 

 7 email 配置好, smtp要自己去配置的,我用的是qq邮箱

Python代码   收藏代码
  1. EMAIL_USE_TLS = True  
  2. EMAIL_HOST = 'smtp.qq.com'  
  3. EMAIL_PORT = 25  
  4. EMAIL_HOST_USER = '547900303@qq.com'  
  5. EMAIL_HOST_PASSWORD = 'hzppuevkhrqubdcd'  
  6. DEFAULT_FROM_EMAIL = EMAIL_HOST_USER  
  7.   
  8. SITE_ID = 1  

 

8

python manage.py check_permissions
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值