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.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

django_wordpress_auth-0.1.0-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.0.tar.gz.

File metadata

File hashes

Hashes for django-wordpress-auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 64f220539d8bdab0323f287253ebe7b2286ee782f722da2d34961d8aa87fb4ef
MD5 f1a930f542c9170655cb3c22e9370f80
BLAKE2b-256 b3c357409c08ef50ec7050b7219d0dcb59427b486bd8b0e1be2249235899d0c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_wordpress_auth-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a205818f124bfac4b90078e4aca0f0cfbe1278030a2bfda299f7ff51834ea3c9
MD5 d3418a51851062186a1ad2a7c85b49e5
BLAKE2b-256 1a966c72aeb67e316484f9dfd1498e969cdd880e2ca2457575f33a8145bf40b1

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