Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Failed to import a model into a view DJANGO

Newbie to Django here.

I am trying to import a model into views to use it. However I am facing problems doing so.

First of all, here is the structure of my folder :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

project structure

webpage folder structure

When I try to import one of my models into views with:

from .models import model_i_want

I get :

ImportError: attempted relative import with no known parent package

if I try

from webpage.models import model_i_want 

I get :

ModuleNotFoundError: No module named 'webpage'

if I try to import models like this

import .models 

I get this error

setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

My webapp is added in the settings, and everything was running smoothly while following the Django official tutorial. I know I should be reading the documentation and figure it out but I can’t seem to understand all of it yet and I am still trying to get used to Django.

Thank you and have a nice day!

>Solution :

Pls check the manage.py file and set the following
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘path to settings file’)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading