开发者

Django Module Error (and Trying to Learn from Guides Using Obsolete Versions)

开发者 https://www.devze.com 2023-03-06 10:48 出处:网络
I am trying to learn Django, but reading guides with a basis in versions different than the current 1.3 is becoming a bit of a pain.

I am trying to learn Django, but reading guides with a basis in versions different than the current 1.3 is becoming a bit of a pain.

I have been told that Pra开发者_运维知识库ctical Django is supposed to be forward-compatible, at least as far as 1.2.5. I recently found a link to the book’s source code at https://bitbucket.org/ubernostrum/practical-django-projects/src/. I tried setting up a server and got this:

>python manage.py runserver

Error: No module named coltrane

Specifically in this case, and perhaps more generally, what can I do to learn Django 1.3 from the guide—and others— based on a now-obsolete version?

(I already have experience reading some guides where I would suddenly receive errors that I hadn’t learnt enough Django to troubleshoot, which stops me from proceeding. The recent mandatory CSRF—which obviously is not mentioned in older literature—is one of these examples.)

If anyone has any experience dealing with this, I’d be interested to hear their general experiences.


This is nothing to do with obsolete versions. Coltrane is a module that you build as you read the book, or by installing that code. Since you got the error 'No module named coltrane', you clearly have not installed it properly. However, without knowing what you've done, it's impossible to know where you went wrong.

Django has a policy of backwards compatibility, and certainly nothing has changed since version 1.1 that would prevent you from installing the coltrane code.


I had a somewhat difficult time learning the basics and outdated tutorials and typos didn't help. I haven't run through the version for 1.3, but I'd like to assume that the tutorials in django docs are correct for the current version.

In regards to the coltrane app, make sure that 'coltrane', is listed in the INSTALLED_APPS section of you settings.py and that the coltrane directory is in your project directory.

Project Dir

> coltrane dir

>> coltranes files

> settings.py

> urls.py

> other files, etc.


You likely forgot to update your PYTHONPATH python variable. To do this simply run the following command:

PYTHONPATH=/path/to/pythoncode/:$PYTHONPATH

Where the path to pythoncode is your path to the directory where you installed your coltrane app. This all works for me as of Django 1.4. It is recommened to set this path variable on your user logon, such as inside your .bash_profile file, that way you do not have to run the command every time you want to use your app.


I found out that there was a typo in __init__.py ( it was __init.py__) because of which this error was popping up. After correcting the error and setting up pythonpath, it worked as expected

0

精彩评论

暂无评论...
验证码 换一张
取 消