1

I am trying to understand this piece of code written in python in a Django App

from . import views

I haven't come across anything like this in the python documentation. Can somebody explain ?

rnevius
  • 26,578
  • 10
  • 58
  • 86
Tomarinator
  • 782
  • 1
  • 11
  • 28

2 Answers2

1

It's a relative import. It lets you import modules from the same package without specifying the package name. So, if you're in the foo.views module, instead of:

from foo.models import Model

you can do:

from .models import Model

This lets you change the package name without refactoring all the imports in that package.

DeRauk
  • 373
  • 1
  • 8
0

This was introduced with PEP-328, and describes a relative import.

Essentially, it means: from the current package/directory import views.

rnevius
  • 26,578
  • 10
  • 58
  • 86