Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:25:12+00:00 2026-05-24T11:25:12+00:00

I still didn’t get django form preview with google app engine to work. I

  • 0

I still didn’t get django form preview with google app engine to work. I didn’t see a working example and my attempts to use django form preview with google app engine failed since I couldn’t translate the request handler usage from django to gae. I’m getting a form preview but it won’t render:

        <html><body><form method="POST" action="/preview">
    <table>
<django.contrib.formtools.preview.FormPreview object at 0x3c5ca50>
    </table><input type="submit"></form></body></html>

The code that generates the HTML above is:

import cgi

from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

from google.appengine.ext.db import djangoforms

class Item(db.Model):
    name = db.StringProperty()
    quantity = db.IntegerProperty(default=1)
    target_price = db.FloatProperty()
    priority = db.StringProperty(default='Medium',choices=[
      'High', 'Medium', 'Low'])
    entry_time = db.DateTimeProperty(auto_now_add=True)
    added_by = db.UserProperty()

class ItemForm(djangoforms.ModelForm):
    class Meta:
        model = Item
        exclude = ['added_by']

from django.contrib.formtools.preview import FormPreview
class PreviewHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write('<html><body>'
                                '<form method="POST" '
                                'action="/preview">'
                                '<table>')
        self.response.out.write(FormPreview(ItemForm()))
        self.response.out.write('</table>'                                    
                                '<input type="submit">'
                                '</form></body></html>')



class ItemPage(webapp.RequestHandler):
    def get(self):
        query = db.GqlQuery("SELECT * FROM Item ORDER BY name")
        for item in query:
            self.response.out.write('<a href="/edit?id=%d">Edit</a> - ' %
                                    item.key().id())
            self.response.out.write("%s - Need to buy %d, cost $%0.2f each<br>" %
                                    (item.name, item.quantity, item.target_price))

class EditPage(webapp.RequestHandler):
    def get(self):
        id = int(self.request.get('id'))
        item = Item.get(db.Key.from_path('Item', id))
        self.response.out.write('<html><body>'
                                '<form method="POST" '
                                'action="/edit">'
                                '<table>')
        self.response.out.write(ItemForm(instance=item))
        self.response.out.write('</table>'
                                '<input type="hidden" name="_id" value="%s">'
                                '<input type="submit">'
                                '</form></body></html>' % id)

    def post(self):
      id = int(self.request.get('_id'))
      item = Item.get(db.Key.from_path('Item', id))
      data = ItemForm(data=self.request.POST, instance=item)
      if data.is_valid():
          # Save the data, and redirect to the view page
          entity = data.save(commit=False)
          entity.added_by = users.get_current_user()
          entity.put()
          self.redirect('/items.html')
      else:
          # Reprint the form
          self.response.out.write('<html><body>'
                                  '<form method="POST" '
                                  'action="/edit">'
                                  '<table>')
          self.response.out.write(data)
          self.response.out.write('</table>'
                                  '<input type="hidden" name="_id" value="%s">'
                                  '<input type="submit">'
                                  '</form></body></html>' % id)

def main():
    application = webapp.WSGIApplication(
                                         [('/', PreviewHandler),
                                          ('/edit', EditPage),
                                          ('/items.html', ItemPage),
                                          ],
                                         debug=True)

    run_wsgi_app(application)

How should I implement the PreviewHandler?
Thank you in advance

UPDATE: Since django has form preview, could I take the template from the django framework and built on it or make my own template? For instance how ta enable that user presses the back button to make changes that also should initiate a validation

<input type="button" value="&lt;-- Go back" name="back" onClick="history.back()" />

<input type="submit" name="validate" value='{% trans "Go" %}' />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:25:12+00:00Added an answer on May 24, 2026 at 11:25 am

    The Django documentation for FormPreview can be found here. It makes it clear that FormPreview is intended to be subclassed and used as a handler, which you can’t do in webapp – it’s specific to the Django framework. You certainly can’t just instantiate a FormPreview object with your form and expect the string representation to be useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really new to .NET, and I still didn't get the hang about how
I've read about SetScrollRange but still didn't get what the range (min, max) is
I'm studying for a test and I'm still didn't get it why public key
After long investigations and reading this question I still didn't get a good solution
Seems like I still didn't get the pointers in C right. I want the
I've read quite a lot about in-app billing and testing but I still didn't
Yesterday I submitted this problem, got terrific responses but my code still didn't work.
I've read many answers to similar questions, but still didn't get to the answer
I've already started similar topic , but still didn't find final solution... So here
Concepts didn't make the C++0x standard, but Boost still provides The Boost Concept Check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.