Reputation: 557
I know this is a strange question but I am lost on what to do. i cloned pinry... It is working and up . I am trying to find django.views.generic. I have searched the directory in my text editor, I have looked in django.views. But I cannot see generic (only a folder with the name "generic"). I cant understand where the generic file is . It is used in many imports and to extend classes but I cannot find the file to see the import functions. I have a good understanding of files and imports and i would say at this stage I am just above noob level. So is there something I am missing here. How come i cannot find this file? If i go to from django.core.urlresolvers import reverse, I can easly find this but not eg : from django.views.generic import CreateView
Where is generic?
Upvotes: 1
Views: 83
Reputation: 16993
Try running this from a Python interpreter:
>>> import django.views.generic
>>> django.views.generic.__file__
This will show you the location of the gerneric
as a string path. In my case the output is:
'/.../python3.5/site-packages/django/views/generic/__init__.py'
If you look at this __init__.py
you will not see the code for any of the generic *View
classes. However, these classes can still be imported from the path django.views.generic
(if I am not mistaken, this is because the *View
classes are part of the __all__
list in django/views/generic/__init__.py
). In the case of CreateView
, it is actually in django/views/generic/edit.py
, although it can be imported from django.views.generic
, because of the way the __init__.py
is set up.
This is technique is generally useful when you want to find the path to a .py
file. Also useful: if you use it on its own in a script (print(__file__)
), it will give you the path to the script itself.
Upvotes: 3