一个快速的“n”脏django应用程序,用于在测试时在不同用户之间切换
django-userswitch-fork的Python项目详细描述
一个快速的“n”脏django应用程序,用于测试时在不同用户之间切换。
- “又快又脏”。只包括中间件。就这样!
- 提供带有用户列表的选择框。
- 用户列表可以在settings中定义,也可以加载所有用户。
- 仅当settings.DEBUG为True 时才有效
要求
django 1.2
安装
要安装最新版本:
pip install git+git://github.com/ikraftsoft/django-userswitch#egg=django-userswitch
也可以使用pip或easy_install:
pip install django-userswitch easy_install install django-userswitch
设置和使用
将userswitch中间件添加到settings.py中的MIDDLEWARE_CLASSES中的默认中间件之后:
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ... 'userswitch.middleware.UserSwitchMiddleware', )
也可以将USERSWITCH_OPTIONSdict添加到设置中。py:
USERSWITCH_OPTIONS = { 'css_class': '', # CSS class to be added to the switcher widget. Default='userswitch'. 'css_inline': '', # Inline css for the switcher widget, if any 'content_types': (), # a tuple of content-type for which to render switcher widget. Default = ('text/html', 'application/xhtml+xml') 'auth_backend': '', # Custom auth backend if any. Default = 'django.contrib.auth.backends.ModelBackend' 'replace_text': '', # Text to replace with the widget, default add to end "body" tag. 'users': (), # List of usernames(as strings) to be shown in the switcher widget. If its empty, all users are loaded. 'force_on': False, # Turns on USERSWITCH even if DEBUG = False, 'onchange_redirect_url': '/' # The url to redirect the user to onchange of user selection. }
注意:选项css_inline的默认值提供了一些基本的绝对值 定位。要更改这些选项,请指定css_inline选项 手动或重写类中的position,top,right。 用!important在css_class中指定。
就这些!