Confused about the import syntax in django for Render()

Viewed 28

Im trying to understand the period in from django.shortcuts import render

Does it mean from the django directory in the shortcuts file?

Or does it mean from the django directory, from the shortcuts directory, import the render file?

1 Answers

In this case it means from the django package in the shortcuts module import the render function. However that isn't a definition that applies to all import statements of the same structure.

A package is roughly speaking a directory containing 1 or more modules.

A module in python is roughly any .py file.

So your first guess was right, however it isn't consistent. For example one common django import statement is:

from django.views import View

but you won't find a View module inside the django.views directory.

View is actually a class that is defined in the django.views.generic.base module.

Related