-
Notifications
You must be signed in to change notification settings - Fork 1
userena
tulpar edited this page Apr 13, 2015
·
1 revision
Date: 2013-09-14 Title: Django-userena 的使用 Tags: Django,userena Category: It
先Clone Github上的源码,运行Demo看看效果,
进入demo目录
pip install -r requirements.txt
(再装一个html2text)
pip install html2text
python manage.py runserver
然后再自己搭一个,如下步骤
pip install django-userena
’userena’,
’guardian’,
’easy_thumbnails’,
AUTHENTICATION_BACKENDS = (
'userena.backends.UserenaAuthenticationBackend',
'guardian.backends.ObjectPermissionBackend',
'django.contrib.auth.backends.ModelBackend',
)
ANONYMOUS_USER_ID = -1
The above is used to get django-guardian working (another Django-Userena dependency that’s automatically installed to control permissions)
3. create a new app for your Django-Userena app named 'accounts'.and add it to your INSTALLED_APPS tuple in your settings.py file.
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)
AUTH_PROFILE_MODULE = 'accounts.MyProfile'
LOGIN_REDIRECT_URL = '/accounts/%(username)s/'
LOGIN_URL = '/accounts/signin/'
LOGOUT_URL = '/accounts/signout/'
(r'^accounts/', include('userena.urls')),
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'yourgmailpassword'
##added by Tulpar,20140514
import os
settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'public/media/')
MEDIA_URL = '/media/'
##added by Tulpar,20140514
from django.conf import settings
urlpatterns += patterns('',
url(r"^media/(?P<path>.*)$","django.views.static.serve",{"document_root": settings.MEDIA_ROOT,}),
)
That's All
##Errors
decoder jpeg not available```
1、先卸载安装的Pillow
pip uninstall Pillow
2、安装JPEG和FREETYPE2库
sudo apt-get install libjpeg-dev
sudo apt-get install libfreetype6-dev
3.重新安装Pillow
pip install -I pillow
1.installed app里加
#added by Tulpar,20140601
'easy_thumbnails'
2.settins.py里加
##added by Tulpar,20140601
import os
settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'public/media/')
MEDIA_URL = '/media/'
###后台如果是使用Xadmin,就得自行register一下,如:
adminx.py
#-*- coding: UTF-8 -*-
#from django.contrib import admin
# Register your models here.
import xadmin
from models import MyProfile
class MyProfileAdmin(object):
#search_fields=('name','category','content')
#prepopulated_fields = { 'message': ['name'] }##learned at http://www.b-list.org/weblog/2008/dec/24/admin/
#exclude = ('created_by',)
#actions = [Songda, ]
list_display = ('user','favourite_snack')
list_display_links = ('user',)
ordering = ("-user",)
list_filter=('user',)#该属性指定可以过滤的列的名字, 系统会自动生成搜索器
search_fields=('user',)#属性指定可以通过搜索框搜索的数据列的名字, 搜索框搜索使用的是模糊查找的方式, 一般用来搜素名字等字符串字段
list_export = ('xls', 'xml', 'json')#该插件在数据列表页面提供了数据导出功能, 可以导出 Excel, CSV, XML, json 格式.
# 这会显示一个下拉列表, 用户可以选择3秒或5秒刷新一次页面.
refresh_times = (3, 5,500)
list_editable = ('favourite_snack')
show_detail_fields = ['user',]#该插件可以在列表页中显示相关字段的详细信息, 使用 Ajax 在列表页中显示.
xadmin.site.register(MyProfile,MyProfileAdmin)