How to Import Data from Another App in Django


In this article, we go over how to import data from another app in Django.

So, let's say, we currently are in the file in the Blog app of our website project directory.

Into this file, we want to import data from another app in our website, the Store app.

How do we import data from the Store app to the Blog app?

It's very simple. Django makes it very simple to communicate data throughout the entire project directory.

Let's say we created a form, named CustomerInfo, in the page in the Store app. And we want to import this form into the page in the Blog app.

The code to do this is shown below.

So, from the file in the Store app, we import the form, CustomerInfo.

So you first have to specify the keyword, from, followed by the App name, followed by a ., followed by the file where the data is located, followed by the keyword import, followed by the name of the data.

The full code is shown below.

So this is the full code to utilize the CustomerInfo form from the file in the Store app.

So, you can see that it is pretty simple to import data from another app in Django.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...