一个快速的“n”脏django应用程序,用于在测试时在不同用户之间切换

django-userswitch-fork的Python项目详细描述


一个快速的“n”脏django应用程序,用于测试时在不同用户之间切换。

  • “又快又脏”。只包括中间件。就这样!
  • 提供带有用户列表的选择框。
  • 用户列表可以在settings中定义,也可以加载所有用户。
  • 仅当settings.DEBUGTrue
  • 时才有效

要求

django 1.2

安装

要安装最新版本:

pip install git+git://github.com/ikraftsoft/django-userswitch#egg=django-userswitch

也可以使用pipeasy_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选项 手动或重写类中的positiontopright。 用!importantcss_class中指定。

就这些!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用Java8流API对嵌套列表进行筛选   java如何使用CXF框架使用HTTP基本身份验证保护的web服务?   比较JAVA中的XML,输出:changelog   Springboot中特定异步请求的java设置超时   java为什么使用洋红?   C/C++与java的学习   java试图使用Camel编写一个简单的HTTPS服务器   java Hystrix仪表板   与java MongoDB相关的扩展问题   java外键级联删除在OpenJPA/Postgresql中未按预期工作   我怎样才能下载。xml文件并使用Java解析网页(如html)?   java实现了xml层次结构,它有一个带有级别号的有序列表   将Java Web项目从Maven迁移到Ant