Can I embed php code in my Django templates?

827 views
Skip to first unread message

Rachel Willmer

unread,
Oct 17, 2006, 7:29:50 AM10/17/06
to django...@googlegroups.com
I've got a website which is written in Django (love it!) but I'd like
to be able to use that look-and-feel to cover the blog part of the
website which is hosted in WordPress.

Is it possible to include PHP code in the Django templates?

Or is there another way (which doesn't involved migrating the blog to Django)?

TIA
Rachel

oli...@obeattie.com

unread,
Oct 17, 2006, 11:56:20 AM10/17/06
to Django users

James Bennett

unread,
Oct 17, 2006, 12:59:15 PM10/17/06
to django...@googlegroups.com
On 10/17/06, Rachel Willmer <rwil...@gmail.com> wrote:
> Is it possible to include PHP code in the Django templates?

Well.

It's probably possible, just not pretty. One thing you might do is
write a custom template loader which calls out to /usr/bin/php and
runs PHP over the contents before returning the Template object for
Django to work with, but that would probably be quite a bit of work.

Another option, and maybe a nicer one, would be to look at the work
Ian Bicking has been doing recently to produce a gateway that lets PHP
apps speak WSGI; he's got an experimental "PyWordpress" that runs
Wordpress under WSGI: http://blog.ianbicking.org/pywordpress.html

Finally, you could ditch WP entirely and use inspectdb +
django.contrib.admin to manage the blog, and do all the templating via
Django, but of course you'd lose (or have to re-implement) any WP
templating features you were relying on.

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

Malcolm Tredinnick

unread,
Oct 17, 2006, 10:48:52 PM10/17/06
to django...@googlegroups.com
On Tue, 2006-10-17 at 12:29 +0100, Rachel Willmer wrote:
> I've got a website which is written in Django (love it!) but I'd like
> to be able to use that look-and-feel to cover the blog part of the
> website which is hosted in WordPress.
>
> Is it possible to include PHP code in the Django templates?

This external template loader example might be useful for you:
http://code.djangoproject.com/ticket/2440 (it's also linked off the
front page of the Wiki if you lose it later).

Regards,
Malcolm


Rachel Willmer

unread,
Oct 18, 2006, 4:35:49 AM10/18/06
to django...@googlegroups.com
Excellent, I'll give it a go

Thanks
Rachel

Reply all
Reply to author
Forward
0 new messages