Django1.3添加app提示模块不存在的解决方法
使用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版本以上的童鞋遇到问题最好阅读官网手册,网上一般找不到解决方案。
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
用python实现学生管理系统
学生管理系统相信大家学各种语言的时候,练习总是会写各种管理系统吧,管理系统主要有对数据的增删查改操作,原理不难,适合作为练手的小程序数据的结构要保存数据就需要数...
[阅读全文]
-
-
-
-
-
-
-
-
-
网友评论