I found it surprisingly easy to do a simple integration of Django with an existing WordPress blog. I use Django to display content from WordPress’s database. I’ll explain how I integrated them and what made things easy.
Who am I?
PHP user 2002-2006
Django user since 2006 (0.95)
Maintain ~20 live Django websites (all are at least 1.6, many started pre-1.0)
What I did
Client had an old WordPress blog with a custom theme we built back in the day (yuck!) and a Django website we built.
Needed to provide a consistent navigation and style between the two
Needed to make it easy to maintain. (one database, common base template, and avoid writing PHP)
Decided to use Django templates for the entire public-facing side of the website, but keep WordPress for editing and managing the content of the blog.
I could have used the-real-django-wordpress package, but I wanted to see how much work it would take if I started from scratch using ./manage.py inspectdb. I spent a few hours tweaking models until things worked and had Django naming conventions, but in the end it allowed me to have full control of the models.
Views are pretty simple: Post.objects.filter(post_type='post', post_status='publish')
Needed to write code to parse WordPress “shortcodes” for images embeds.
Comments are the only place where Django writes to the database. A fairly basic ModelForm does the job. They are moderated through the WordPress admin.
To keep things easy to maintain, I decided to use no WordPress plugins, and write no PHP code (except wp-config.php).
Keep PHP/WordPress running using php-fpm, php-mysql, and a few lines of nginx config. WordPress auto-installs security updates.
What makes integrating Django and WordPress easy?
It turns out WordPress maintains a well-established easy-to use editing user experience out of the box:
autosave, revisions, and rollback
custom key/value “meta data” extra fields
WordPress has put 13-years of thought into its Post model so I didn’t have to.
Easy to “migrate” an existing WordPress blog (just start using the database :).
I ended up having a lot more time to focus on making a great front-end and more time to work on other sections of the website.
Can shut off WordPress, and the website is still there.
Can always ditch WordPress and go django-only in the future if needed.
It’s PHP. It’s two different worlds, but I’m trying to keep php-side customization minimal.
I can’t support every possible feature of WordPress (like widgets), though I can add features when I need them.
WordPress database can change over time, breaking the website, though has been pretty stable recently.
Crazy idea for the future
A few anecdotes on content vs application (if there’s time)
If it shows up on a search engine result page, it’s probably content.
Content parts of websites are much easier to make than application-like pieces.
With content, it’s sometimes possible to serve the exact same content to every user, and then cache it as if it’s static content.
(though be sure not to cache security tokens!)
simple cache validation strategy: any change in the admin clears the entire cache.
pure static content doesn’t have a “Vary:” header.
In my situation, Django handles the content, and WordPress is the application.