Wednesday, June 29, 2011

Re: unable to import Modules Present in subdirectores

A couple of basic python things for you to check:

1: You must have a file named "__init__.py" (it may be an empty file)
in any directory that is to occur before a "." in an import statement.
The presence of this file makes the directory a "package", just like
having a name ending in ".py" makes a file a module. You can import
modules or sub-packages from packages, but not from directorys that
aren't packages, unless the directory is explicitly on sys.path.

2: Python imported names are case sensitive, even if your filesystem
is not. Thus you cannot import a module named "Views.py" using the
name "views", as in "polls.views". You would have to use, for
example, "polls.View". If the name of the package is "Polls" then you
would have to use "Polls.Views".

Bill

On Wed, Jun 29, 2011 at 3:51 AM, srinivasan panneer
<srinivasan.pan@hotmail.com> wrote:
> Hi Guys
> I am very new to Python and Django and having problem with importing modules
> in my project,
> I am following the tutorial, which i downloaded from django website. Where I
> have the following folder hierarchy in my Django project.(using Pycharm IDE)
>
> HelloWorldDjango
> HelloWorldDjango/HelloWorldDjangoApp
> HelloWorldDjango/HelloWorldDjangoApp/polls
> I am able to import modules from my site folder which is
> HelloWorldDjangoApp, but having problem in importing from the subfolders.
> For example I have Views.py in polls directory and iam not able to import
> it.
> It is unable to find the modules in the subdirectories like  polls.views
> What do i do?   i believe some Env variable has to be modified, Because
> currently the    sys.path has path upto my HelloWorldDjangoApp directory..
> What do i do for subdirectories.
> Thank you in advance..
>
>
> Regards,
> Srini
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment