Is there a way to see imported modules/files from the django shell?

684 views Asked by At

I have some lines of code that I use to practice django_rest_framework and I just pasted them in the python shell from python manage.py shell.

I have gotten some errors and would like to know what imports I already have.

Is there a function to figure out what was imported? This may be applicable to a python shell as well that isn't obtained from django.

This may not be necessary but here is the example code that I pasted in the shell while following this tutorial:

from .api_basic.models import Article
from .api_basic.serializers import ArticleSerializer
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser

a = Article(
    title='Article Title',
    author = 'Parwiz',
    email = '[email protected]'
)
b = Article(
    title='New Title',
    author = 'John',
    email = '[email protected]'
)

a.save()
b.save()

serializer = ArticleSerializer(a)
print(serializer.data) # gives a dict
content = JSONRenderer().render(serializer.data)


serializer2 = ArticleSerializer(Article.objects.all(), many=True)
content2 = JSONRenderer().render(serializer.data)
1

There are 1 answers

0
Someshwaran S On BEST ANSWER

You can check the imports using the built in dir() function. It actually lists out all the variables, classes, functions, imports etc. declared in the current python shell.

Reference

enter image description here