How Should i import the Model Class on django to other py file to use it?

I wanted to insert model instance to database from a file. i wrote a python program to do so by importing models. but every time i get this error;

ModuleNotFoundError: No module named 'exams'

i have tried putting the file in the same folder;

then i got "Relative import error"

the expected result was to save model instance in the database.

You need to include more details, at least your files' paths. But if we assume that both models.py and I guess views.py files are in the same folder you should use:

from .models import exams

Unless what you are trying to import is the django models. In that case you use:

from django.db import models

As I said questiong is poorly written and needs improvement to better understand your problem.

Back to Top