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.

Files for django-wordpress-auth, version 0.1.31
Filename, size File type Python version Upload date Hashes
Filename, size django_wordpress_auth-0.1.31-py2.py3-none-any.whl (7.9 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size django-wordpress-auth-0.1.31.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page