参考 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_BACKENDS
, INSTALLED_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/'
5
在accounts.models中加入
- from __future__ import unicode_literals
- from django.db import models
- from django.contrib.auth.models import User
- from django.utils.translation import ugettext as _
- from userena.models import UserenaBaseProfile
- class MyProfile(UserenaBaseProfile):
- user = models.OneToOneField(User,
- unique=True,
- verbose_name=_('user'),
- related_name='my_profile')
- favourite_snack = models.CharField(_('favourite snack'),
- max_length=5)
6 接着url配置
在urls.py中加入
- url(r'^accounts/', include('userena.urls')),
7 email 配置好, smtp要自己去配置的,我用的是qq邮箱
- EMAIL_USE_TLS = True
- EMAIL_HOST = 'smtp.qq.com'
- EMAIL_PORT = 25
- EMAIL_HOST_USER = '547900303@qq.com'
- EMAIL_HOST_PASSWORD = 'hzppuevkhrqubdcd'
- DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
- SITE_ID = 1
8
python manage.py check_permissions