ImportError and Django make me crazy

OK, I have the following directory structure (this is a django project):

-> project
-> app

and in the application folder there is a scraper.py file, which should refer to the class defined in models.py

I am trying to do the following:


import urllib2
import os
import sys
import time
import datetime
import re
import BeautifulSoup

sys.path.append('/home/userspace/Development/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'

from project.app.models import ClassName

and this code just doesn't work. I get an error message:

Traceback (most recent call last):
  File "scraper.py", line 14, in 
    from project.app.models import ClassName
ImportError: No module named project.app.models

This code above was used, but it broke somewhere along the line, and I am very confused why I have problems. On SnowLeopard using python2.5.

+3
source share
3
import sys
sys.path.append ('/path/to/the/project')
from django.core.management import setup_environ
import settings
setup_environ(settings)

from app.models import MyModel
+3

Whoa whoa whoa. - . - . Pinax , django.

, , - . , , - import local_settings.

, pinax settings.py...

import os.path
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

, , , .

models.py scraper.py , import models import models as app_models, - scraper.py(, django.db.models). Python?

- , , django, ... import... statement:

from app import models

, - .py.

+1

, project /home/userspace/Development/. , .

, project ( ) __init__.py, - app.

EDIT: , : Python script :

import project
import project.app as app
import project.app.models as models
models.__dict__.keys()

? , ? , ?

0
source

Source: https://habr.com/ru/post/1739783/


All Articles