Django1.3添加app提示模块不存在的解决方法

WBOY
Release: 2016-06-16 08:42:27
Original
1125 people have browsed it

使用Django添加应用的时候,一直提示Error: No module named myapp。意思是找不到这个名字的应用,可是我已经startapp成功,并且系统已经创建相应的目录

复制代码 代码如下:

D:\Python27\Scripts\website>python manage.py syncdb
Error: No module named myapp

难道官方的文档有错,我manage.py startapp myapp已经成功,并且已经创建目录与文件。
并在settings.py的INSTALLED_APPS里添加应用,如下代码
复制代码 代码如下:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'website.myapp',
)

最后一行website.myapp就是我新添加的。谷歌搜索了好久,也没有解决这个问题。最后无奈只好去官方读读docs,才发现这是新版与旧版的区别问题。
Django1.3版之前需要project.app这么写
Django1.3版后只需要app这么写即可
最后把settings.py的INSTALLED_APPS修改为
复制代码 代码如下:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'myapp',
)

然后执行
复制代码 代码如下:

python manage.py syncdb

OK,成功。

后记

我下载了最新版本的Django1.4,手册教程是旧版本的。一步步跟着教程安装出现了问题,一开始以为是自己哪里漏命令或者输错命令了,重试N次还是提示找不到应用。最后无奈只好到官网去仔细阅读英文手册(靠翻译软件)最终发现这是版本问题。

经过这几天调试发现新版与旧版有不少区别,而且也是新手及容易犯的错误,而网上极少的教程又是以低版本为主,加上不少站点采集千篇一律,这也可能是因为Python在国内做站的几乎没有或者极少数。所以个人建议接触Django1.3版本以上的童鞋遇到问题最好阅读官网手册,网上一般找不到解决方案。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!