Re: Problems with simple "hello world" test - "ImportError: Could not import settings"

171 views
Skip to first unread message

Mike Dewhirst

unread,
Sep 10, 2012, 6:45:48 PM9/10/12
to django...@googlegroups.com
On 11/09/2012 1:31am, DJ-Tom wrote:
> Hi,
>
> I'm new to django and python at the same time (Nightmare <g>) and
> currently struggling to get a basic understanding of how everything
> works and how the different components are connected to each other.
>
> My setup is a s follows:
>
> - Apache 2.2 running as a service under Windows 7
> - mod_wsgi
> - Python 2.7.3
> - django 1.4.1
> - web server docroot under d:\wwwroot
> - test project under d:\wwwroot\djtest\djtest set up with
>
> django-admin.py startproject djtest
>
>
> Basically I think that almost everything is set up correctly, things
> like "python manage.py syncdb" work without probkems, I could activate
> django.contrib.admin and create the database without errors - only if I
> try to access the admin I get the following apache error.log:
>
> mod_wsgi (pid=6804): Exception occurred processing WSGI script
> 'D:/wwwroot/djtest/djtest/wsgi.py'.
> Traceback (most recent call last):
> File
> "D:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py",
> line 219, in __call__
> self.load_middleware()
> File
> "D:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py",
> line 39, in load_middleware
> for middleware_path in settings.MIDDLEWARE_CLASSES:
> File
> "D:\\Python27\\lib\\site-packages\\django\\utils\\functional.py",
> line 184, in inner
> self._setup()
> File
> "D:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line
> 42, in _setup
> self._wrapped = Settings(settings_module)
> File
> "D:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line
> 95, in __init__
> raise ImportError("Could not import settings '%s' (Is it on
> sys.path?): %s" % (self.SETTINGS_MODULE, e))
> ImportError: Could not import settings 'djtest.djtest.settings' (Is
> it on sys.path?): No module named djtest.djtest.settings
>
>
> wsgi.py looks like this:
>
>
> import os
> import sys
>
> path = 'd:/wwwroot/djtest/djtest/'
> if path not in sys.path:
> sys.path.append(path)
>
> os.environ.setdefault("DJANGO_SETTINGS_MODULE",
> "djtest.djtest.settings")

Try dropping this down to "djtest.settings". Also make sure you have a
file in each of your folders called __init__.py

This tells Python the folder is part of the package.


>
> # This application object is used by any WSGI server configured to
> use this
> # file. This includes Django's development server, if the
> WSGI_APPLICATION
> # setting points here.
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
>
>
> HELP! :-)))
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/fl5wkcGjpuQJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

DJ-Tom

unread,
Sep 11, 2012, 4:13:42 AM9/11/12
to django...@googlegroups.com
Am Dienstag, 11. September 2012 00:43:44 UTC+2 schrieb Mike Dewhirst:

Try dropping this down to "djtest.settings". Also make sure you have a
file in each of your folders called __init__.py

This tells Python the folder is part of the package.

Sorry - but this does not help. Just to be sure that I'm not missing anything essential, this is all I have so far:

d:\djtest\
   manage.py
   data.sql
   \djtest\
      __init__.py
      settings.py
      urls.py
      wsgi.py

Am I correct to assume that this should be sufficient to call at least the /admin/ interface?

I have activated this in urls.py:  url(r'^admin/', include(admin.site.urls)),

And this in settings.py: 'django.contrib.admin',

But as django does not seem to be able to find settings.py... hmmmmm

Jian Chang

unread,
Sep 11, 2012, 4:19:57 AM9/11/12
to django...@googlegroups.com
"d:/wwwroot/djtest/djtest/" was already in system path, so I think you should set DJANGO_SETTINGS_MODULE like this: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

try it!

2012/9/11 DJ-Tom <event...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/tEB1E_DacVAJ.
330.gif

DJ-Tom

unread,
Sep 11, 2012, 11:33:31 AM9/11/12
to django...@googlegroups.com


Am Dienstag, 11. September 2012 10:20:16 UTC+2 schrieb Chang.Jian:
"d:/wwwroot/djtest/djtest/" was already in system path, so I think you should set DJANGO_SETTINGS_MODULE like this: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

try it!


Ok... GREAT! Now it works :-) (well... sort of, more below... ) but I had to restart Apache to make config changes effective... is that "normal"?

I think important things like "you have to restart the webserver to make changes life" should go into the tutorial in BIG RED LETTERS <g>

Now I get a "regular" Django exception:

NameError: name 'admin' is not defined

Daniel Roseman

unread,
Sep 11, 2012, 11:40:19 AM9/11/12
to django...@googlegroups.com
On Tuesday, 11 September 2012 16:33:31 UTC+1, DJ-Tom wrote:


Am Dienstag, 11. September 2012 10:20:16 UTC+2 schrieb Chang.Jian:
"d:/wwwroot/djtest/djtest/" was already in system path, so I think you should set DJANGO_SETTINGS_MODULE like this: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

try it!


Ok... GREAT! Now it works :-) (well... sort of, more below... ) but I had to restart Apache to make config changes effective... is that "normal"?

I think important things like "you have to restart the webserver to make changes life" should go into the tutorial in BIG RED LETTERS <g>


The tutorial, by design, doesn't mention Apache at all. That's because it's heavily recommended that you use the built-in devserver for development, for precisely this reason. That's what it's for.
--
DR. 

DJ-Tom

unread,
Sep 13, 2012, 5:25:21 AM9/13/12
to django...@googlegroups.com

Ok... GREAT! Now it works :-) (well... sort of, more below... ) but I had to restart Apache to make config changes effective... is that "normal"?

I think important things like "you have to restart the webserver to make changes life" should go into the tutorial in BIG RED LETTERS <g>


The tutorial, by design, doesn't mention Apache at all. That's because it's heavily recommended that you use the built-in devserver for development, for precisely this reason. That's what it's for.


Basically I always try to have the same environment for development as I also use for actual production - I'm lucky that my projects are small enough so i can do that :-) to avoid last minute surprises when trying to deploy the application to the public.

James Bennett

unread,
Sep 13, 2012, 5:31:53 AM9/13/12
to django...@googlegroups.com
On Thu, Sep 13, 2012 at 4:25 AM, DJ-Tom <event...@gmail.com> wrote:
> Basically I always try to have the same environment for development as I
> also use for actual production - I'm lucky that my projects are small enough
> so i can do that :-) to avoid last minute surprises when trying to deploy
> the application to the public.

This is a fine thing to do once you understand Django and know what
you're doing with it. But for a beginner's tutorial aimed at someone
who knows nothing about Django, the development server is far more
ideal since it avoids throwing in a pile of "oh, and before you even
start, go learn how to set up and run Apache and a bunch of other
stuff so that you can use a production server stack to learn Django"
:)

As such, the tutorial doesn't and shouldn't mention trying to set up
Apache or other production deployment setups. It should simply teach
people how to write Django applications and understand how the pieces
of the framework fit together.

DJ-Tom

unread,
Sep 19, 2012, 10:37:05 AM9/19/12
to django...@googlegroups.com

I have now found extensive documentation as to why and how Apache has to be configured with Django and mod_wsgi here http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Stephen Anto

unread,
Sep 19, 2012, 1:52:21 PM9/19/12
to django...@googlegroups.com
Hi,

There are only 7 steps ahead to say 'Hello World' via Django project. 

Visit http://www.f2finterview.com/web/Django/17/ its tells how to make simple django project with seven steps. Thank you for visiting

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qPvYvgWTXS8J.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Reply all
Reply to author
Forward
0 new messages