WebFaction
Community site: login faq

Hi,

I am trying to setup mail2script work with Django. My test script works but when I try to use Django models in script I get ImportError: No module named django.contrib.auth.models.

I think I have to somehow add Django to path in the script or something but couldn make it work yet.

This is how I have tried it.

PROJECT_ROOT = '/home/my_user/webapps/django/myproject'
DJANGO_SETTINGS_MODULE = '/home/my_user/webapps/django/myproject/settings_prod'

def setup_django():
    sys.path.append('/home/my_user/lib/python2.6/django')
    sys.path.append(PROJECT_ROOT)
    keys = os.environ.keys()
    from re import search
    for key in keys:
        if not search('DJANGO_SETTINGS_MODULE', key):
            os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE

Any help?

asked 02 Dec '10, 20:19

tiparkki
2138
accept rate: 0%


It appears that the script specified in your Control Panel email configuration does not exist (that is; the path is entered incorrectly).

Also, you are explicitly adding '/home/my_user/lib/python2.6/django' to sys.path, which does not allow the importing of "django.contrib.auth.models", but instead "contrib.auth.models". To fix this, you will probably want to remain with the standard '/home/my_user/lib/python2.6' so as not to include the contents of the django module, but rather the module itself.

permanent link

answered 02 Dec '10, 21:01

ryans ♦♦
5.0k93260
accept rate: 43%

edited 02 Dec '10, 21:07

thanks ryans! There was typo in email configuration, thanks for pointing it out. Now it worked when I specified the path like you proposed. Thanks a lot!

(02 Dec '10, 21:08) tiparkki

You should try setting the path at the begging of the script.

import sys
sys.path.append('/home/username/webapps/django/lib/python2.6/site-packages/')
permanent link

answered 02 Dec '10, 20:25

johns
5.3k312
accept rate: 23%

edited 02 Dec '10, 20:26

Did not help, still same error.

(02 Dec '10, 20:33) tiparkki
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×260
×4

question asked: 02 Dec '10, 20:19

question was seen: 3,377 times

last updated: 26 Nov '12, 16:03

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM