Cant Import mysite.urls

83 views
Skip to first unread message

Jon Blake

unread,
Sep 10, 2012, 7:29:12 PM9/10/12
to django...@googlegroups.com
Working through getting Django to work with Apache, mod_wsgi and Oracle database back end. When I enter my site URL, I get a "ImportError at /" page, with an exception value of "No module named mysite.urls".

Part 3 of the tutorial refers to line ROOT_URLCONF = 'mysite.urls', which I have in my settings.py module. I don't have a file mysite.urls. The tutorial then goes on to discuss editing utls.py, (which I do have) and states that Django will load this module (utils.py) because ROOT_URLCONF points to it. I don't understand that bit - what's the connection between mysite.urls and utils.py, and how does Django import mysite.urls if it does not exist?

TIA,
  Jon

Jon Blake

unread,
Sep 11, 2012, 12:44:22 AM9/11/12
to django...@googlegroups.com
Thanks, Patrick. My reference to utils.py should have been to urls.py, which I have in my mysite app package.

I'm seeing this import error on mysite.urls when I'm attempting to get Apache + mod_wsgi to serve my app. I don't remember seeing this error with the development server when I first tried out the tutorials. Probably got my configs wrong, somewhere in my second try.

I'll start a new app, now that I know a little bit more about how this all works. It's a steep learning curve!


On Tuesday, September 11, 2012 10:59:02 AM UTC+10, patrick wrote:
On Monday, September 10, 2012 8:29:12 PM UTC-3, Jon Blake wrote:
Working through getting Django to work with Apache, mod_wsgi and Oracle database back end. When I enter my site URL, I get a "ImportError at /" page, with an exception value of "No module named mysite.urls".

Part 3 of the tutorial refers to line ROOT_URLCONF = 'mysite.urls', which I have in my settings.py module. I don't have a file mysite.urls. The tutorial then goes on to discuss editing utls.py, (which I do have) and states that Django will load this module (utils.py) because ROOT_URLCONF points to it. I don't understand that bit - what's the connection between mysite.urls and utils.py, and how does Django import mysite.urls if it does not exist?


It can be a bit confusing the first time you run into it, but "mysite.urls" isn't a file. It's a namespaced import path. So in this case, it is looking for an urls.py file in the mysite directory.

In the tutorial it's assumed that you named your project mysite. If you called it something else (say tutorial), the import path would be "tutorial.urls".

If you are using Django 1.4 and followed the tutorial by using the django-admin.py startproject command (which builds a project skeleton for you), the urls.py file should be in the same directory as your settings.py file.

I couldn't find a reference to utils.py in the tutorial so I assume it must be an accidental typo and probably the cause of the error you're seeing.

patrick

unread,
Sep 11, 2012, 7:37:56 PM9/11/12
to django...@googlegroups.com
On Tuesday, September 11, 2012 1:44:22 AM UTC-3, Jon Blake wrote:
Thanks, Patrick. My reference to utils.py should have been to urls.py, which I have in my mysite app package.

I'm seeing this import error on mysite.urls when I'm attempting to get Apache + mod_wsgi to serve my app. I don't remember seeing this error with the development server when I first tried out the tutorials. Probably got my configs wrong, somewhere in my second try.

I'll start a new app, now that I know a little bit more about how this all works. It's a steep learning curve!

It will get better. At one point, I found that the biggest problem I was having that I was expecting things to be harder than they actually were.

You might want to also take a look at the tutorials at: http://lightbird.net/dbe/

They were written for Django 1.2, but should still work in Django 1.4 and get you to build other types of apps, so you'll get more insight into what Django has to offer. 

Jon Blake

unread,
Sep 14, 2012, 12:24:42 AM9/14/12
to django...@googlegroups.com
Hi Patrick,
  just got Apache + mod_wsgi to serve part 1 of the tutorial as per Django document "How to use Django with Apache and mod_wsgi". Your point taken about assuming things are going to be harder than they actually are - my redo of part 1 of the tutorial worked pretty well "out of the box" after a good night's sleep.

Now to get serving the admin files to work...

Tom Evans

unread,
Oct 17, 2012, 7:32:02 AM10/17/12
to django...@googlegroups.com
On Tue, Oct 16, 2012 at 5:20 PM, go scholarship
<the.schol...@gmail.com> wrote:
> i'am using django 1.4, and i just want to get currently logged in user,and
> associating those users with tasks.

If you have questions, please send a new email to the list, do not
hijack threads by arbitrarily replying to them with new, different
questions.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages