1
You need to add the init.py in dev folder. Because it treated as a python package. Next you need to add your django project path in fillDB.py like this,
Root
ββββββ builds
β βββ admin.py
β βββ __init__.py
β βββ models.py
β βββ tests.py
β βββ views.py
βββ computerbuilder
β βββ dev
β β βββ db.txt
β β βββ fillDB.py
β βββ __init__.py
β βββ settings.py
β βββ urls.py
β βββ views.py
β βββ wsgi.py
βββ manage.py
βββ requirements.txt
Follow the above folder structure,
And also you need to set the django environment variable to this file.
fillDB.py
import sys
import os
if __name__ == "__main__":
sys.path.append('/path/Root')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "computerbuilder.settings")
from builds.models import BuildsTable
mobo = BuildsTable.objects.all()
print mobo
Hope this help you
1
Check you sys.path to see whether there have you path or not. Every time you run your python project, python will append you current path to the sys.path. And once you quit the python enviroment, python will remove the path you appended in.
Your problem is you run just run fillDB.py, python just append β../computerbuilder/devβ into sys.path, so python can not find builds module.
The solution is move your fillDB.py file to the same level as builds folder
βββ builds
βββ fillDB.py
β βββ admin.py
β βββ __init__.py
β βββ models.py
β βββ tests.py
β βββ views.py
βββ computerbuilder
β βββ dev
β β βββ db.txt
β βββ __init__.py
β βββ settings.py
β βββ urls.py
β βββ views.py
β βββ wsgi.py
βββ manage.py
βββ requirements.txt
Hope it can help you
- [Answered ]-Django update view and passing context
- [Answered ]-What is happening in this urlpatterns list of Python Django urls.py file?
- [Answered ]-Content of a Django template disappear immediately after rendering