最近学习Django,首先就是搭建环境
1起初就是安装过python,版本为2.7
2安装Django,正在python中测试版本成功如下:
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 11, 2, u'final', 0)
>>>
3 继续创建Django项目,项目名为first
django-admin.py startproject project first
4接着用pycharm打开,给runserver作出配置
5点击运行first项目,遇到import错误(着重敲黑板)如下:
try: import django except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) raise这时,我开始查资料,各种百度,没看见什么有效的解决办法。。。
解决思路:
(1)python版本的问题,因为编译器自带了python2.6,尝试换了自己安装的版本
(2)点击运行,又报错,是script parameter的错误(和谐:百度不可靠),发现这个参数原来是如下:
[auth]
changepassword
createsuperuser
[contenttypes]
remove_stale_contenttypes
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
结合百度,果断选择runserver.
(3)最后运行结果如下:
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 09, 2017 - 03:33:13
Django version 1.11.2, using settings 'project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
执行成功