How to Import Data from Another App in Django



Python


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

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

Into this urls.py 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 models.py page in the Store app. And we want to import this form into the views.py page in the Blog app.

The code to do this is shown below.



So, from the models.py 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 models.py 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...