ModuleNotFoundError/ImproperlyConfigured /ImportError
doublyU opened this issue ยท 1 comments
When tried to import models module to views.py, this way I got_ the error of ImproperlyConfigured.
**from django.shortcuts import render
from models import Car
Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, word. You are at the polls index.')**
This Is the error here below ๐
(django3) C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls>python views.py
Traceback (most recent call last):
File "C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls\views.py", line 2, in
from models import Car
File "C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls\models.py", line 4, in
class Car(models.Model):
File "C:\Users\Salam Taofeek\Desktop\django3\lib\site-packages\django\db\models\base.py", line 127, in new
app_config = apps.get_containing_app_config(module)
File "C:\Users\Salam Taofeek\Desktop\django3\lib\site-packages\django\apps\registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\Salam Taofeek\Desktop\django3\lib\site-packages\django\apps\registry.py", line 137, in check_apps_ready
settings.INSTALLED_APPS
File "C:\Users\Salam Taofeek\Desktop\django3\lib\site-packages\django\conf_init_.py", line 87, in getattr
self.setup(name)
File "C:\Users\Salam Taofeek\Desktop\django3\lib\site-packages\django\conf_init.py", line 67, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested 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.
I tried another way to import it again this way ๐
**from django.shortcuts import render
from .models import Car
Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, word. You are at the polls index.')**
This is the error that I got here ( ImportError: attempted relative import with no known parent package)๐
(django3) C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls>python views.py
Traceback (most recent call last):
File "C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls\views.py", line 2, in
from .models import Car
ImportError: attempted relative import with no known parent package
Lastly I tired to import it this way too ๐
**from django.shortcuts import render
from gview.models import Car
Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, word. You are at the polls index.')**
Here is the error that I got (moduleNotFoundError) ๐
(django3) C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls>python views.py
Traceback (most recent call last):
File "C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls\views.py", line 2, in
from gview.models import Car
ModuleNotFoundError: No module named 'gview'**m .models import Car
ImportError: attempted relative import with no known parent package
Lastly I tired to import it this way too ๐
**from django.shortcuts import render
from gview.models import Car
Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, word. You are at the polls index.')**
Here is the error that I got (moduleNotFoundError) ๐
(django3) C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls>python views.py
Traceback (most recent call last):
File "C:\Users\Salam Taofeek\Desktop\django3\django_projects\mysite\polls\views.py", line 2, in
from gview.models import Car
ModuleNotFoundError: No module named 'gview'
We do not provide student help here in github