Reputation: 1466
I am using virtual Environment to develop the project. Using python3 and Django 1.9.7
I am splitting views into multiple files. Below is the tree structure.
|-- urls.pyc
`-- Views
|-- DashboardView.py
|-- DashboardView.pyc
|-- __init__.py
|-- __init__.pyc
|-- __pycache__
| |-- DashboardView.cpython-34.pyc
| |-- __init__.cpython-34.pyc
| `-- VehicleView.cpython-34.pyc
|-- VehicleView.py
`-- VehicleView.pyc
Inside __init__.py
file -
from VehicleView import *
from DashboardView import *
When I am activating virtual environment and running code it throws me below error -
File "/home/rana/DjangoProject/FirstChoice/MyFirstCar/MyFirstCarBackEnd/Views/__init__.py", line 1, in <module>
from VehicleView import *
ImportError: No module named 'VehicleView'
If I do not activate the virtual environment and run the code, it runs without any error. Default django version 1.8.4 and python 2.7.6
Upvotes: 1
Views: 47
Reputation: 16743
In your __init__.py
try to use local imports instead, this may be a problem if you are using python3
in your virtual environment.
from .VehicleView import *
from .DashboardView import *
Besides file and module names in python should follow snake case convention, only classes should use CamelCase.
from .vehicle_view import *
form .dashboard_view import *
Upvotes: 2