pip install django-wordpress
python
INSTALLED_APPS = [
...
'wordpress',
...
]
DATABASES = {
'default': {
...
'OPTIONS': {
'read_default_file': '/path/to/your/wp-config.php',
},
},
}
python manage.py startapp mywordpressplugin
python
INSTALLED_APPS = [
...
'wordpress',
'mywordpressplugin',
...
]
python
from django.db import models
from wordpress.models import Post
class MyCustomModel(Post):
custom_field = models.CharField(max_length=255)
python
from django.contrib import admin
from mywordpressplugin.models import MyCustomModel
admin.site.register(MyCustomModel)
python manage.py migrate
python manage.py runserver
python
from django.shortcuts import render
from wordpress.views import PostDetail
class MyCustomPostDetail(PostDetail):
template_name = 'mywordpressplugin/my_post_detail.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['custom_data'] = 'Additional Data'
return context
python
from django.urls import path
from mywordpressplugin.views import MyCustomPostDetail
urlpatterns = [
...
path('post/<slug:slug>/', MyCustomPostDetail.as_view(), name='post_detail'),
...
]