[Django]-Add form to django-flatpages

3👍

Return the right context from the form page view.

This is the context sent to flatpages’ template (where f is the flatpage instance)

f.title = mark_safe(f.title)
f.content = mark_safe(f.content)

c = RequestContext(request, {
    'flatpage': f,
})

in your view you can easily return a (unsaved) flatpage instance with all attrs you need.

f = FlatPage()
f.title = ""
f.content = ""
....
c = RequestContext(request, {
    'flatpage': f,
})

0👍

If you are going to be using forms, then you don’t need to use flatpage – use a regular view with the flatpage template, and RequestContext as your context.

Leave a comment