I'm trying to add a nice admin interface to an existing Pyramid project. I created a test project using pcreate -s alchemy -s pyramid_fa fa_test and then copied all the extra files created into my project and altered them to be suitable.
Everything looks to be good and dandy until I try to add a formalchemy route:
config.formalchemy_model("/foo", package='bar',
model='bar.models.specific_models.Thingy',
**settings)
Then I get: ImportError: No module named forms
My question is: How do I fix this? Or what is the correct way to add an admin interface?
I've googled around a bunch to no avail...
Here's relevant code:
fainit.py:
from bar import models, faforms
import logging
def includeme(config):
config.include('pyramid_formalchemy')
config.include('bar.fainit')
config.include('fa.jquery')
config.include('pyramid_fanstatic')
model_view = 'fa.jquery.pyramid.ModelView'
session_factory = 'bar.models.access.DBSession'
## register session and model_view for later use
settings = {'package': 'bar',
'view': model_view,
'session_factory': session_factory,
}
config.registry.settings['bar.fa_config'] = settings
config.formalchemy_admin("/admin", models=models, forms=faforms,
**settings)
# Adding the package specific routes
config.include('shop.faroutes')
log.info('formalchemy_admin registered at /admin')
faroutes.py
from bar import models
import logging
log = logging.getLogger(__name__)
def includeme(config):
settings = config.registry.settings.get('shop.fa_settings}}', {})
config.formalchemy_model("/alerts", package='shop',
model='shop.models.super_models.Alert',
**settings)
log.info('shop.faroutes loaded')
And the traceback:
Starting subprocess with file monitor
Traceback (most recent call last):
File "../bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5a1', 'console_scripts', 'pserve')()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 316, in run
global_conf=vars)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 340, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/home/sheena/WORK/tv_guys_env/shop/shop/__init__.py", line 30, in main
includeme(config)
File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 8, in includeme
config.include('shop.fainit')
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
c(configurator)
File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 24, in includeme
config.include('shop.faroutes')
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
c(configurator)
File "/home/sheena/WORK/tv_guys_env/shop/shop/faroutes.py", line 12, in includeme
**settings)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/util.py", line 507, in wrapper
result = wrapped(self, *arg, **kw)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 58, in formalchemy_model
view=view, models=[model], model=model, **kwargs)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 85, in formalchemy_admin
forms = config.maybe_dotted('%s.forms' % package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 848, in maybe_dotted
return self.name_resolver.maybe_resolve(dotted)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 316, in maybe_resolve
return self._resolve(dotted, package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 323, in _resolve
return self._zope_dottedname_style(dotted, package)
File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 372, in _zope_dottedname_style
__import__(used)
ImportError: No module named forms
It sounds like it's looking for you to create a forms module at shop.faroutes.forms.
Related
I tried peewee with flask for two days, but I failed till now. The code is as the follows:
import click
from flask import Flask
from flask.cli import FlaskGroup
from playhouse.flask_utils import FlaskDB
from models import *
from config import config
flask_db = FlaskDB()
def create_app(config_name):
application = Flask(__name__)
application.config.from_object(config[config_name])
flask_db.init_app(application)
flask_db.connect_db()
flask_db.database.create_tables([User])
flask_db.database.close()
#application.route('/')
def index():
return "hello world!"
return application
def create_cli_app(info):
return create_app("develop")
#click.group(cls=FlaskGroup, create_app=create_cli_app)
def cli():
pass
#cli.command()
def initdb():
flask_db.connect_db()
flask_db.database.create_tables([User])
flask_db.database.close()
if __name__ == "__main__":
cli()
When I run it with the CLI: python manage.py run, I got the following errors:
(venv) ➜ /Users/yw/Documents/web git:(master) ✗ p manage.py run
Traceback (most recent call last): File "manage.py", line 46, in
cli() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 716, in call
return self.main(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 345, in main
return AppGroup.main(self, *args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 696, in main
rv = self.invoke(ctx) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 889, in invoke
return ctx.invoke(self.callback, **ctx.params) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 534, in invoke
return callback(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/decorators.py",
line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 534, in invoke
return callback(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 388, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) File
"/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 124, in init
self._load_unlocked() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 148, in _load_unlocked
self._app = rv = self.loader() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 201, in load_app
rv = self.create_app(self) File "manage.py", line 30, in create_cli_app
return create_app("develop") File "manage.py", line 19, in create_app
flask_db.database.create_tables([User]) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 3765, in create_tables
create_model_tables(models, fail_silently=safe) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 5175, in create_model_tables
m.create_table(**create_table_kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 4845, in create_table
if db.sequences and pk is not False and pk.sequence: AttributeError: 'FlaskDB' object has no attribute 'sequences'
Indeed, I just want to initiate the DB by using flask.cli tool. As you see, if I use the command “python manage.py initdb”, I can only get the same error output as above.
So what is the meaning of "'FlaskDB' object has no attribute ‘sequences'"? What should I do?
Thanks for your help!
It seems that your User model doesn't have correct database.
With FlaskDB, your User model should inherit FlaskDB().Model
instead of defining class Meta: database = database.
database = FlaskDB()
class User(database.Model):
pass
I'm trying to learn to work with Neo4jdatabase in my django projects. I installed Neo4Django from github repository. and following its neo4j tutorial when I try to create a new object from my model I encounter with this error:
KeyError: 'GremlinPlugin'
I'm using Python 2.7, Django Version 1.5.8, Pycharm 3
My model is:
class Movie(models.NodeModel):
# name of the movie
title = models.StringProperty()
and my console code for creating the object is:
from nodes_app.models import Movie
movie = Movie.objects.create(title='a')
and this is the console output for the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\manager.py", line 43, in create
return self.get_query_set().create(**kwargs)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\query.py", line 1307, in create
return super(NodeQuerySet, self).create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\query.py", line 416, in create
obj.save(force_insert=True, using=self.db)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 325, in save
return super(NodeModel, self).save(using=using, **kwargs)
File "C:\Python27\lib\site-packages\django-1.5.8-py2.7.egg\django\db\models\base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 341, in save_base
self._save_neo4j_node(using)
File "<string>", line 2, in _save_neo4j_node
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 98, in trans_method
ret = func(*args, **kw)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\db\models\base.py", line 369, in _save_neo4j_node
typesToIndex=type_names_to_index)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 179, in gremlin_tx
return self.gremlin(script, tx=True, **params)
File "C:\Python27\lib\site-packages\neo4django-0.1.8-py2.7.egg\neo4django\neo4jclient.py", line 127, in gremlin
ext = self.extensions.GremlinPlugin
File "C:\Python27\lib\site-packages\neo4jrestclient\client.py", line 2176, in __getattr__
self._dict[attr] = ExtensionModule(self._extensions[attr], self._auth)
KeyError: 'GremlinPlugin'
It seems that the Neo4j Django driver depends on the Gremlin plugin on the Neo4j server. Starting with Neo4j 2.0, Gremlin has been removed from the distribution but is still available as a contribution package, see the instructions there.
I'm trying to integrate django-celery into an existing site and I'm coming up against an error that I can't seem to get fixed.
For context, I went through the Django first steps and the test project was successful, ie everything worked as it should.
Now, in my existing project, I can't get the celery worker running from the command line:
manage.py celery worker --loglevel=info --settings=myproject.settings.dev_settings
When i run that I get the following stack trace and error:
Traceback (most recent call last):
File "C:\sites\corecrm\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 453, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\djcelery\management\commands\celery.py", line 22, in run_from_argv
['%s %s' % (argv[0], argv[1])] + argv[2:],
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 901, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "C:\Python27\lib\site-packages\celery\bin\base.py", line 187, in execute_from_commandline
return self.handle_argv(prog_name, argv[1:])
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 893, in handle_argv
return self.execute(command, argv)
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 868, in execute
return cls(app=self.app).run_from_argv(self.prog_name, argv)
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 148, in run_from_argv
return self(*args, **options)
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 118, in __call__
ret = self.run(*args, **kwargs)
File "C:\Python27\lib\site-packages\celery\bin\celery.py", line 220, in run
return self.target.run(*args, **kwargs)
File "C:\Python27\lib\site-packages\celery\bin\celeryd.py", line 153, in run
return self.app.Worker(**kwargs).run()
File "C:\Python27\lib\site-packages\celery\apps\worker.py", line 162, in run
self.app.loader.init_worker()
File "C:\Python27\lib\site-packages\celery\loaders\base.py", line 130, in init_worker
self.import_default_modules()
File "C:\Python27\lib\site-packages\djcelery\loaders.py", line 138, in import_default_modules
self.autodiscover()
File "C:\Python27\lib\site-packages\djcelery\loaders.py", line 141, in autodiscover
self.task_modules.update(mod.__name__ for mod in autodiscover() or ())
File "C:\Python27\lib\site-packages\djcelery\loaders.py", line 176, in autodiscover
for app in settings.INSTALLED_APPS])
File "C:\Python27\lib\site-packages\djcelery\loaders.py", line 195, in find_related_module
return importlib.import_module('%s.%s' % (app, related_name))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\sites\corecrm\people\tasks.py", line 15, in <module>
from people.models import Customer, CustomerCsvFile, CustomerToTag, get_customer_from_csv_row
File "C:\sites\corecrm\people\models.py", line 163, in <module>
UserProfile._meta.get_field_by_name('username')[0]._max_length = 75
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 351, in get_field_by_name
cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 380, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 469, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 483, in _fill_related_many_to_many_cache
for klass in get_models(only_installed=False):
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 197, in get_models
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate
self.load_app(app_name)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\sites\corecrm\booking\models.py", line 17, in <module>
from people.models import Customer, UserProfile
ImportError: cannot import name Customer
To try and work out what the booking/models.py script sees in people I added the following at the start:
import people
print 'path: %s' % people.__path__
for item in dir(people):
print item
and that gives me the following output:
path: ['C:\\sites\\corecrm\\people']
__builtins__
__doc__
__file__
__name__
__package__
__path__
path: ['C:\\sites\\corecrm\\people']
__builtins__
__doc__
__file__
__name__
__package__
__path__
however, when I run manage.py shell --settings=myproject.settings.dev_settings I get the following output:
path: ['C:\\sites\\corecrm\\people']
__builtins__
__doc__
__file__
__name__
__package__
__path__
path: ['C:\\sites\\corecrm\\people']
__builtins__
__doc__
__file__
__name__
__package__
__path__
models
As you can see the models module is available at the end of the 2nd list for the shell command (and I've confirmed this is also the case for manage.py commands other than celery). How would I make sure that module is available at the same point when I run the celery command?
EDIT: I've now also set up this project on an Ubuntu VM and I'm getting the same error when I try to run the worker manage command. Any ideas? Anyone?
ANOTHER EDIT: I've pasted the code for booking/models.py and people/models.py at http://pastebin.com/fTVVBtB4
I'm pretty sure this line is your problem:
File "C:\sites\corecrm\people\models.py", line 163, in <module>
UserProfile._meta.get_field_by_name('username')[0]._max_length = 75
While you're still busy importing from people.models, this line (in particular get_field_by_name) forces Django to evaluate the model and setup all relationships between that model and it's related models. This, in turn, forces an import of Customer in people.models, while you're still busy importing that exact model. This is what results in an ImportError.
For a working solution you'll need to post your models.py.
Why does this error only occur with celery? I can't say for sure without some more information, but my best guess is that Celery handles importing everything slightly different (Django probably doesn't import Customer, CustomerCsvFile, CustomerToTag and get_customer_from_csv_row all at once) and that this exposes the bug in your code.
EDIT/SOLUTION:
I would remove this line:
UserProfile._meta.get_field_by_name('username')[0]._max_length = 75
And move it to the instance level, into the __init__ method:
class UserProfile(AbstractUser):
def __init__(self, *args, **kwargs):
self._meta.get_field_by_name('username')[0]._max_length = 75
super(UserProfile, self).__init__(*args, **kwargs)
If the cause of the issue is indeed what I think it is, this will fix the circular import while providing the same functionality. If the max_length functionality gets broken somehow (most likely because internally a max_length validator is added to CharField and _max_length is changed too late) I would instead override the complete username field in the init method:
class UserProfile(AbstractUser):
def __init__(self, *args, **kwargs):
super(UserProfile, self).__init__(*args, **kwargs)
self._meta.get_field_by_name('username')[0] = models.CharField(max_length=75, etc.)
I'm trying to run Selenium tests for a Django app on production server.
I am getting a syntax error on the finally: clause.
I don't see where the error is and all the tests ran fine in development.
Here is the code:
def activate_revision(self, user, revision):
self.title = revision.title
self.tagnames = revision.tagnames
self.body = self.rendered(revision.body)
self.active_revision = revision
# Try getting the previous revision
try:
prev_revision = NodeRevision.objects.get(node=self, revision=revision.revision-1)
update_activity = True
# Do not update the activity if only the tags are changed
if prev_revision.title == revision.title and prev_revision.body == revision.body \
and prev_revision.tagnames != revision.tagnames and not settings.UPDATE_LATEST_ACTIVITY_ON_TAG_EDIT:
update_activity = False
except NodeRevision.DoesNotExist:
update_activity = True
finally:
if update_activity:
self.update_last_activity(user)
self.save()
Here is the traceback:
$ python manage.py test forum
Traceback (most recent call last):
File "/usr/lib/python2.4/logging/__init__.py", line 731, in emit
msg = self.format(record)
File "/usr/lib/python2.4/logging/__init__.py", line 617, in format
return fmt.format(record)
File "/usr/lib/python2.4/logging/__init__.py", line 408, in format
s = self._fmt % record.__dict__
KeyError: 'funcName'
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_lookup method hasn't been updated to take `connection` and `prepared` arguments.
new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_value method hasn't been updated to take `connection` and `prepared` arguments.
new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
Traceback (most recent call last):
File "manage.py", line 13, in ?
execute_manager(settings)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/spirituality/lib/python2.7/South-0.7.3-py2.7.egg/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 358, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 247, in build_suite
app = get_app(label)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 129, in get_app
self._populate()
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/__init__.py", line 2, in ?
from question import Question ,QuestionRevision, QuestionSubscription
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/question.py", line 1, in ?
from base import *
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/base.py", line 349, in ?
from node import Node, NodeRevision, NodeManager
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/node.py", line 383
finally:
^
SyntaxError: invalid syntax
First part of the traceback suggests that it's Python 2.4 on production. As per my comment above, the problem is that try..except..finally is only for Python 2.5 and newer. Upgrade production or rewrite the code to nest try..except inside an outer try..finally.
I'm going through Django tutorial and using PyDev Eclipse plugin for development.
For interactive testing I use "Interactive shell with Django" which is accessed by Right click on PyDev project -> Django -> Shell with Django environment.
And here is the problem I encountered ("lemonanas" is my project name, "polls" is my app name):
>>from lemonanas.polls.models import Poll, Choice
>>Poll.objects.filter(id=1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "F:\Python27\lib\site-packages\django\db\models\manager.py", line 141, in filter
return self.get_query_set().filter(*args, **kwargs)
File "F:\Python27\lib\site-packages\django\db\models\query.py", line 561, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "F:\Python27\lib\site-packages\django\db\models\query.py", line 579, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1170, in add_q
can_reuse=used_aliases, force_having=force_having)
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1058, in add_filter
negate=negate, process_extras=process_extras)
File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1225, in setup_joins
field, model, direct, m2m = opts.get_field_by_name(name)
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 296, in get_field_by_name
cache = self.init_name_map()
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 326, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 401, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "F:\Python27\lib\site-packages\django\db\models\options.py", line 415, in _fill_related_many_to_many_cache
for klass in get_models():
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 167, in get_models
self._populate()
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 76, in load_app
app_module = import_module(app_name)
File "F:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named polls
If I use default shell, executing "manage.py shell" - all works fine. But default shell not such comfortable as "Interactive shell with Django".
I noticed that "Interactive shell with Django" does not add my app folder (polls) to python path. And I guess this is the essense of problem. But don't know how to entirely solve all "import/pythonpath/etc." problems with "Interactive shell with Django".
Hope you can help me.
Thanks.
Customize the python path, eclipse uses to include the path to the project. (Not each app, just the project folder. - The one that contains settings.py)
In Eclipse, right click your project, goto PyDev-> Set as source folder