django安装创建工程
django官方文档:https://docs.djangoproject.com/en/4.0/
1、前提条件:已经安装好python环境
2、先执行python -m django –version,看是否之前安装过Django。
如果这行命令输出了一个版本号,证明你已经安装了此版本的 Django;如果你得到的是一个“No module named django”的错误提示,则表明你还未安装。
3、如果没安装,安装djiango版本:pip install Django==3.2.9

4、创建django工程

创建完成后,进入到指定文件夹下面可以看到以下文件夹,表示创建成功
![]()

5、在CMD框中,进入到工程根目录,输入python manage.py runserver,出现下列提示,表示已经成功启动
6、启动验证,在chrome中输入 http://127.0.0.1:8000/(具体地址看启动时返回的地址上图红框中地址),显示django主页,表示启动成功。
报错说明
1、WARNING: You are using pip version 21.3.1; however, version 22.1.2 is available
执行升级命令:C:\Users\nantian\AppData\Local\Programs\Python\Python37\python.exe -m pip install --upgrade pip
2、命令未找到:django-admin
django-admin should be on your system path if you installed Django via python setup.py. If it’s not on your path, you can find it in site-packages/django/bin, where site-packages is a directory within your Python installation. Consider symlinking to django-admin from some place on your path, such as /usr/local/bin.
If django-admin doesn’t work but django-admin.py does, you’re probably using a version of Django that doesn’t match the version of this documentation. django-admin is new in Django 1.7.
3、'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件
出现这个问题一般是环境变量配置问题,需要将python的环境变量加到path中,例如:

4、pip 下载报“connection to pypi.org time out“
1.配置镜像文件这样就可以直接使用pip的指令来完成包的安装和数据的升级
2.首先在cmd中输入set,查看userprofile的位置,一般就在系统盘(C盘)下面的USER
3.在该目录下面建立一个pip的文件夹
4.在该文件下面建立一个pip.ini的文件
5.在该文件中写入如下内容,然后在保存。
===================分隔符中的才是文件内容,但不包括这一头一尾说明前后说明====================
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=tsinghua.edu.cn
===================分隔符中的才是文件内容,但不包括这一头一尾说明前后说明====================
国内常用的pip源如下:
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
如上配置完成后,安装成功:
浙公网安备 33010602011771号