Django Import Error: cannot import name “Shift”
Clash Royale CLAN TAG#URR8PPP
Django Import Error: cannot import name “Shift”
I'm pretty sure it's due to a circular import but I'm not too sure how to solve my issue
in mysite/shifts/models.py
from django.db import models
class Shift(models.Model):
# defines a shift`
in mysite/shifts/scrapes.py
from shifts.models import Shift
I can share more code if you need but I believe the issue is here, I've added my apps to settings.py
and I get this error when I run scrapes.py
as a django-admin command
settings.py
scrapes.py
from shifts.models import Shift
ImportError: No module named 'shifts'
project_structure
mysite
What do you mean set one above?
– Connor McCann
Aug 10 at 9:13
Would you show your folder structure?
– guillermo chamorro
Aug 10 at 14:40
2 Answers
2
from mysite.shifts.models import Shift
This solved that error! I now have an error:
from mysite.shifts.models import Shift ImportError: No module named 'mysite'
I've tried including mysite in installed apps but no luck resolving it.– Connor McCann
Aug 10 at 9:43
from mysite.shifts.models import Shift ImportError: No module named 'mysite'
Okay, use from .models import Shift. The dot is the aktuall app
– Nico Zimmer
Aug 10 at 9:46
Now I've got
SystemError: Parent module '' not loaded, cannot perform relative import
when will this end lol– Connor McCann
Aug 10 at 9:53
SystemError: Parent module '' not loaded, cannot perform relative import
Do you vorgot the dot ? .models import Shift, not from models import Shift.
– Nico Zimmer
Aug 10 at 9:55
. is in there
from .models import Shift
– Connor McCann
Aug 10 at 9:59
from .models import Shift
Use the following line in mysite/shifts/scrapes.py
from .models import Shift
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
it looks like the Python path has been set wrong. You probably have set one above
mysite
.– Willem Van Onsem
Aug 10 at 9:03