my_controller.py is as follow:
from models import Person
david = Person('David')
And my project structure is
app
├── controller
│ └── my_controller.py
│
└── models
└── __init__.py
└── person.py
I must do something wrong because I keep get
ModuleNotFoundError: No module named 'models'
What is the correct way to import class Person to my_controller.py?
PS I am working on ubuntu
You need to use relative import
from . import models
Or it's better to import models that you will user, since it won't visually collide with django.db.models.
from django import forms
from .models import VolunteerBasicInfo
class BasicInfoCollectionForm(forms.ModelForm):
class Meta:
model = VolunteerBasicInfo
...
You also don't need to user brackets with class Meta.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With