I am new to Django, and I'm trying to import one of my models in a script as we do it in views.py. I'm getting an error:
Traceback (most recent call last):
File "CallCenter\make_call.py", line 3, in <module>
from .models import Campaign
ModuleNotFoundError: No module named '__main__.models'; '__main__' is not a package
My file structure is like:
MyApp\CallCenter\
CallCenter contains __init__.py, make_call.py, models.py, views.py and MyApp has manage.py
from twilio.rest import Client
from twilio.twiml.voice_response import VoiceResponse, Say, Dial, Number, VoiceResponse
from .models import Campaign
def create_xml():
# Creates XML
response = VoiceResponse()
campaign = Campaign.objects.get(pk=1)
response.say(campaign.campaign_text)
return response
xml = create_xml()
print(xml)
make_call.py?python make_call.pywithin theCallCenterapp directory won't work.django.setup()) which is required to be able to use your models etc... If you want to run a command-line like script using Django, create a management command so you can run it withmanage.pywhich will do the proper setup for you.