0

I have 2 apps:

friends/apps/loginreg/models.py/User
friends/apps/friends/views.py

I am trying to import the User method into the views.py file.

These are my imports:

from __future__ import unicode_literals
from .models import Friend
from loginreg.models import User
from django.shortcuts import render, redirect

It continues to give error no module named loginreg.models

Md. Rezwanul Haque
  • 2,882
  • 7
  • 28
  • 45
andrewixl
  • 51
  • 5

2 Answers2

0

The 'from' path is wrong, I think. Try from ..loginreg.models import User

You're trying to import from a folder above your current one. You can read more about that here.

Andrew Zick
  • 582
  • 7
  • 23
0
import sys
sys.path.insert(0, '/path/to/application/app/folder')

import file

Python searches the current folder for the modules. This way you can add the path to search your module at runtime

Or you could normally import it the way you are, but in that case you need to make sure that there is a file __init__.py inside the parent folder of your module file. This would allow it to be included as a package. That __init__.py file could be empty. It is just there to tell Python to treat the folder as a package.

More details here.

anon
  • 1,258
  • 10
  • 17