Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine, Python 2.7 runtime, ImportError: cannot import name djangoforms

If I comment out the handlers that use djangoforms everything else seems to work.

The following is my modified app.yaml:

application: xxxxxxx
version: 5
#` -1+1
# runtime: python
runtime: python27
api_version: 1

inbound_services:
- mail

#` +3
libraries:
- name: django
  version: "1.2"

handlers:
- url: /(.*\.(html|css|js|gif|jpg|png|ico))
  static_files: static/\1
  upload: static/.*
  expiration: "1d"
  # expiration: "1m"

- url: .*
  script: main.py

- url: /_ah/mail/.+
  script: lib/handler_mail.py
  login: admin

The following is the excerpt from main.py that I modified:

import os
# dummy, enables django template filters to be registered
os.environ[u'DJANGO_SETTINGS_MODULE'] = u'conf'
#` -2
# from google.appengine.dist import use_library
# use_library('django', '1.2')

from functools import wraps
from appengine_utilities.cache import Cache
from google.appengine.api import taskqueue
from google.appengine.ext.db import djangoforms
...

Here's the trace back from my log: Traceback (most recent call last): File "/base/data/home/apps/s~cirrussecure1/5.354034990641807540/main.py", line 23, in from google.appengine.ext.db import djangoforms ImportError: cannot import name djangoforms

Something I'm doing won't let me import djangoforms but doesn't affect anything else. I Googled it but no one else seems to be having a problem (yet?). Thanks.


@all Found a solution that keeps me going on gae/python 2.7 but I don't like it or the way google handled this part of the release.

I tried wtforms and made some progress trying to get it going with gae/python 2.5 before calling enough.

I then got djangoforms.py (from http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/db/djangoforms.py), dropped it in with my files, and got it to work with gae/python 2.7.

I used the app.yaml shown above. Also had to change {{ form_section }} to {{ form_section|safe }} in two template files.

I guess Django is falling out of favor with the gae team. I could understand if djangoforms was deprecated for a year and then dropped. However, dropping it with out any warning or even any mention in the doc.'s comparing the current release with the previous just isn't a nice thing to do to your customers.

@google Please update your, doc.'s, articles, examples, etc. so others don't have to waste a day like I did.

like image 460
Cirrus Secure Avatar asked Oct 17 '11 21:10

Cirrus Secure


2 Answers

I ended up including this in my app http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/db/djangoforms.py and that got it to work.

like image 29
a.m. Avatar answered Nov 18 '22 11:11

a.m.


The google.appengine.ext.db.djangoforms module is not provided with the Python 2.7. You could patch in a copy yourself, but a better idea would be to modify your form handling code to not rely on it - it's unsupported and frankly a bit of a hack.

like image 186
Nick Johnson Avatar answered Nov 18 '22 11:11

Nick Johnson