10👍
I needed to put the parent directory of mysite on the path. I only had /home/ubuntu/virtenv/webstatic/staticone/mysite
. Now it works when I included
/home/ubuntu/virtenv/webstatic/staticone/
.
import sys
sys.path.append("/home/ubuntu/virtenv/webstatic/staticone/")
print (sys.path)
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','mysite.settings')
import django
django.setup()
from mysite.rango.models import Category,Page
Now it works.
0👍
you can make it dynamic by
import sys
from pathlib import Path
sys.path.append(Path(__file__).resolve().parent.parent.__str__())
print (sys.path)
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','mysite.settings')
import django
django.setup()
from mysite.rango.models import Category,Page
- Where has 'django.core.context_processors.request' gone in Django 1.10?
- Django admin, section without "model"?
- Celery vs. ProcessPoolExecutor / ThreadPoolExecutor
Source:stackexchange.com