Hooking up lamson with django 1.4

北城以北 提交于 2019-12-24 19:45:21

问题


I'm trying to hook-up lamson with django 1.4. I've seen the documentation on hooking up lamson with django and the librelist example from the source, but it seems to use a previous version of django.

I have created a "webapp" project that contains an "emails" app as described in the basic django 1.4 tutorial.

The webapp/webapp/settings.py file contains a reference to the emails application in the installed_apps like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'emails',
)

The lamson application folder contains the webapp folder for the django project. Now, instead of having a "webapp/emails" folder that contains everything like in the librelist example provided by Zed Shaw, i have yet another webapp folder that contains the settings.py, plus the extra application folder (emails) that contains the models and all (this is due to the new directory structure in django 1.4).

In the config/settings.py file for lamson, I have added the following line:

os.environ['DJANGO_SETTINGS_MODULE'] = 'webapp.webapp.settings'

Now, in the my handler code, (app/handlers/my_handler.py), i have imported my models:

import webapp.emails.models

I can create instances from my model correctly, but as soon as i try to save them to the database using my_instance.save(), I get the following error:

File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named emails

Any idea what the problem can be?

Otherwise, is it possible to remove django 1.4 and use django 1.3 to make it work?

Thanks for your help


回答1:


This is setup which worked for me

move webapp and mailserver folders on the same level

mailserver #lamson project
- lamson files
webapp #django 1.4 app
- settings.py ...

In lamson settings.py

import sys
import os
sys.path.append('../webapp')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

now you can access django project modules in lamson handler without any prefix

e.g.

import emails.models


来源:https://stackoverflow.com/questions/11106326/hooking-up-lamson-with-django-1-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!