2π
This is a common mistake because python 3 have stricter rules when it comes to relative imports.
I assume you have a structure like this.
myapp
βββ basics.py
βββ views.py
.. where myapp
is in the root of your project.
Letβs assume basics.py
looks like this.
def do_stuff():
pass
The ways you can import things from basic would then be (views.py
)
from myapp import basics
from myapp.basics import do_stuff
from . import basics
from .basics import do_stuff
# View code ...
I assumed here that basics.py
and views.py
are located in the same package (app
).
When you run a python project your current directory is added to the python path. You will either have to import all the way from the root of your project or use .
to import from the local package/directory.
Also notice in the example that you can import the entire module or just single functions/objects. When importing the entire basics
module you access it using basics.do_stuff()
in the view.
- [Answered ]-Notify user about bounced confirmation emails
- [Answered ]-Query to retrieve neighbors is too slow
- [Answered ]-Pip is rolling back uninstall of setuptools
- [Answered ]-Django Admin: variables/constants inside Django Admin that can be changed
- [Answered ]-My api call doesnot work in javascript but works fine with in postman and browser