tags:

views:

55

answers:

1

Can I call a Flatpage from with a view. Say I have some code like:

def myview(request):

  if request.subdomain != "www":
    return HttpResponseRedirect("http://"+request.subdomain+".mydomain/login/")

  else:
    call the flatpage here...
+4  A: 

You sure can. Just make sure you have the flatpage function included in your view code:

from django.contrib.flatpages.views import flatpage

And stick the following in your else:

return flatpage(request, '/path/to/your/flatpage/')

Or if you'd like to configure the flatpage to use the same URL being called, you can always do it like this:

return flatpage(request, request.path)

I just tested this and it worked just fine. Let me know if it doesn't for you.

bchang