Skip to main content

Django integration with WordPress authentication and roles / capabilities system.

Project description

Introduction

Allows for access in Django to a WordPress installation for checking for things like login status and roles / capabilities.

Requirements

Python Dependencies:

WordPress Dependencies:

Installation

Add your WordPress’s auth keys and salts (found in wp-config.php) to your settings.py.

WORDPRESS_LOGGED_IN_KEY = "rs&^D%jPdu=vk|VVDsdfsdgsdgsdg9sd87f98s7h[Xm$3gT/@1xdasd"
WORDPRESS_LOGGED_IN_SALT = "3]x^n{d8=su23902iu09jdc09asjd09asjd09jasdV-Lv-OydAQ%?~"

Add your WordPress database to DATABASES in settings.py.

DATABASES = {
    'default': {
        ... # default django DB
    },
    'wordpress': {  # must be named 'wordpress'
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'wordpress',
        'USER': '...',
        'PASSWORD': '...',
        'HOST': '...',
        'PORT': 3306,
    }
}

Add the middleware to MIDDLEWARE_CLASSES in settings.py. Make sure it’s placed somewhere after the session middleware.

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    # ...
    'wordpress_auth.middleware.WordPressAuthMiddleware',
)

Finally, add wordpress_auth to INSTALLED_APPS.

INSTALLED_APPS = (
    # ...
    'wordpress_auth',
)

Usage

To restrict a view to a certain role, simply wrap the view in the wordpress_requires_role decorator.

from wordpress_auth.decorators import wordpress_requires_role

@wordpress_requires_role('my_role')
def my_view():
    pass

You can restrict a view to a capability as well.

from wordpress_auth.decorators import wordpress_requires_capability

@wordpress_requires_capability('my_capability')
def my_view():
    pass

Finally, the middleware provides access to the WordPress user via request.wordpress_user.

See models.py for full reference. Some of the redundant naming conventions in the WordPress database have been made simpler as well.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-wordpress-auth-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

django_wordpress_auth-0.1.2-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-wordpress-auth-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django-wordpress-auth-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b5de45e411aae845e29d58f5e3a06eeb861e57a58fea137baea7e36bbe5884eb
MD5 57ad9e22d9af7bd1471fc1998932cedf
BLAKE2b-256 cf93cce1662cd4e3dcb525215071273c014f8d27255fbbcf4a95efa9530dee5a

See more details on using hashes here.

File details

Details for the file django_wordpress_auth-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_wordpress_auth-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cc5fa47950acaf5073263f084cef69eeb5bfaa868c56db97aeafa1a6fd0122b2
MD5 c93504d64689fd7766911b3800a9b00f
BLAKE2b-256 3502318ec7ebe12be903e1bc9d71f59de16ead3fb94c1172340f9bf464f46cc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page