史上最全django安装教程

选择版本

首先由于版本兼容性问题,所以需要安装好对应的django,python,mysql版本才能确保今后程序的顺利运行,其兼容性见下表(表来源于博客)

python3怎么安装locust python3怎么安装django_python


python3怎么安装locust python3怎么安装django_python_02


根据上表,我选择的版本号为

django 3.0.3 (路径:Django1环境)

python 3.7 (路径:Django1环境)

mysql 8.0.17 (路径:C盘下)

安装django和python

为了避免更多的麻烦,我选择利用anaconda新建环境django1,来安装python和django包

1.打开anaconda navigator,点击environment,创建新环境,python版本选择3.7,等待创建成功

python3怎么安装locust python3怎么安装django_mysql_03


2.安装django包,如下图

python3怎么安装locust python3怎么安装django_mysql_04


python3怎么安装locust python3怎么安装django_python3怎么安装locust_05


3.点击apply,等待再点击apply,等待安装

python3怎么安装locust python3怎么安装django_python_06

安装Mysql

mysql的下载:百度网盘, 提取码: uzph

安装MySQL具体步骤参考此博客 安装中遇到的问题:

  1. 第5步中:请将内容中的路径修改为自己解压的后的路径(有2个需要改)
  2. 从第6步开始,请使用管理员身份运行
  3. 第8步中:若提示发生系统错误2XXX,
    方法一:切换路径,cd C:\mysql-8.0.17-winx64\bin

    方法二:有可能是先前安装过MySQL又重新安装,需要修改注册表,在cmd中输入regedit
    选择路径:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL

    点击ImagePath,点击修改将其值修改为你解压后的sql文件路径

使用cmd运行第一个django项目

1.打开anacoanda prompt,激活django1环境

python3怎么安装locust python3怎么安装django_python_07


2.输入:django-admin startproject mysite(见上图),此时mysite项目位于如下图:

python3怎么安装locust python3怎么安装django_django_08


3,进入mysite文件 ->cd mysite ,然后输入python manage.py runserver 127.0.0.1:8000

python3怎么安装locust python3怎么安装django_django_09


4.在浏览器中输入上图网址,回车

python3怎么安装locust python3怎么安装django_python3怎么安装locust_10

使用pycharm运行第一个django项目

1.打开pycharm, 点击文件,点击新项目,接下来步骤如下图(注:create后请选择open in new window)

python3怎么安装locust python3怎么安装django_django_11


2.点击绿色图标,运行项目

python3怎么安装locust python3怎么安装django_python_12


3.运行成功:

python3怎么安装locust python3怎么安装django_python3怎么安装locust_13

若出现错误:
from _sqlite3 import ImportError DLL load failed 找不到指定的模块
参考博客: