Reputation: 57156
Is it possible to have both frameworks available? So that I could have
from google.appengine.ext import webapp
from django.template.loader import render_to_string
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write(render_to_string('some.template'))
and
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world")
running mapped to different URLs?
EDIT: The question basically boils down to how do I implement
urlpatterns = [
# webapp-style handler
(r'/webapp', views.MainPage),
# django
(r'/django', views.hello),
]
Upvotes: 4
Views: 840
Reputation: 34498
Yes! In fact, if you go to the GAE site the "getting started" tutorial shows exactly that! Both libraries are built in, so it's incredibly easy to get up and going with it.
Google App Engine: Getting Started
Upvotes: 0
Reputation: 101139
Certainly - as long as you're not using 0.9.6 in one sub-app and 1.0 (via the use_library call) in the other. Just map URL regular expressions to separate handlers in app.yaml and you're good to go.
Upvotes: 4
Reputation: 12829
Django is just a set of libraries, so in one sense, you can definitely run it on Google App Engine (or any WSGI-compatible web container). However, it won't work if you try to freely mix the two frameworks, as each expects to have total control of the request/response cycle, and has different abstractions for the request lifecycle, session management, etc.
You can use Django to code GAE applications by writing your own WSGI handler module. See this article for a basic rundown on how to have a single Django app answer all requests for your GAE instance.
Mixing the two within a single request isn't going to work, though you could use the Django templating library (or a clone like Jinja) if you just want the front-end to borrow from Django's syntax. Also, you should be able to set up Google app handlers and Django endpoints under different URLs by extending the WSGI dispatcher in the above article. However, I would question whether trying to support two entirely different web frameworks for a single site was really worth the extra complexity.
Upvotes: 1