Forums

Django tutorial not working

Hi, I am following the Django tutorial and am having some difficulty.

I followed all the instructions to the end. Everything works up to the part about configuring views, when I uncomment the views line in urls.py, I start getting the following errors:

TemplateSyntaxError at /admin/
Caught ViewDoesNotExist while rendering: Could not import mysite.myapp.views. Error was: No module named database

The tutorial says to uncomment this line in urls.py:

url(r'^$', 'mysite.myapp.views.home', name='home'),

Which is what I did, although I would note that in the actual urls.py, the actual line of code is:

url(r'^$', 'mysite.views.home', name='home'),

So I added in the myapp part.

HI there -- that sounds like it was able to find the views.py file, that file itself was trying to import something called database. Is there any chance you mistyped datetime?

I don't think so, I re-did the tutorial 3 times and copied and pasted instead of typing just to make sure.

Here is the content of /home/skomes/mysite/myapp/views.py

from datetime import datetime

from django.shortcuts import render

def home(request):

    return render(request, 'home.html', {'right_now':datetime.utcnow()})

If I visit the site right now, I see the error

Could not import mysite.views. Error was: No module named views

...so presumably the problem with the missing myapp is there at the moment?

...the missing myapp that you mentioned in urls.py, that is.

Yes, that was me messing around with it. I changed mysite.myapp.views.home to mysite.views.home to see what the different errors mean.

I just changed it back now and somehow the app/django is working.

Did you change something?

Nope, I didn't change anything. How odd! Is it possible that the error message in your first run-through happened when there was a typo, but your copy/pasted version since then has fixed it?

I don't know, because I was getting the same error just now with the copy pasted version too but again, somehow it is now gone.

Oh well, I'll try to figure it out later, maybe I'll re-run the tutorial to see what I did wrong.

Thanks for the help.

Very odd. Perhaps something's getting cached by your browser? It often helps to shift-refresh in the browser when debugging this kind of stuff.

Ok so the proble was that in tutorial is: url(r'^$', 'mysite.view.home', name='home'),

should be: url(r'^$', 'mysite.views.home', name='home'),

views ... small stupid error