回顾建立项目报错

1、建立虚拟环境

  1. 安装虚拟环境pip install virtualenv
  2. 建立虚拟环境virtualenv venv(venv就是虚拟环境名称,自定义)
  3. 进入虚拟环境venv\Scripts\activate
  4. 安装所需软件:pip install django==1.9.6
  5. 退出deactivate

2、建立项目

  1. 进入虚拟环境,执行命令python django-admin.py startproject znytest,(建立项目),若出现报错找不到django-admin.py,在venv找到复制到当前目录便可
  2. 建立应用 在znytest中执行命令 python manage.py startapp app01 若出现报错django.utils.encoding.DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xd5 in position 9: invalid continuation byte. You passed in 'C:\\Users\\\xd5\xc5\xc4\xfe\xd1\xf4\\znytest\\db.sqlite3' (<type 'str'>)在settings中将数据库改成mysql便可
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'test',    
            'USER': 'root',   
            'PASSWORD': 'root',    
            'HOST': '127.0.0.1',
            'PORT': '3306',
        }
    }
    

      在settings.py同目录下的__init__.py中html

    import pymysql
    pymysql.install_as_MySQLdb()
    

      windows安装mysql:http://www.cnblogs.com/zhangningyang/p/7479112.html#lod6,若出现找不到msvcr120.dll安装vcredist_x64.exe便可,https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=40784python

相关文章
相关标签/搜索