在写了很多次项目之后,今天突然决定重新写,并边写边提交到GitHub,简单总结一下经验,以及中间出现的一些错误。
由于之前没有经验,所以事先在GitHub上新建了仓库。正由于这一步,所以导致了后续的一系列事情。
由于之前在Windows系统上面提前安装了pip,所以个人建议,对于学习python,安装pip真的非常重要
一、创建虚拟环境
由于个人使用的是python3.6
找到想要创建虚拟环境的位置:我是在d盘新建文件夹(虚拟环境)
进入文件夹(虚拟环境)
按住shift+鼠标右键。点击在此处打开shell窗口(win10 的是powershell)
输入: python -m vnev python-django (python-django 是文件夹名称,可以自己定义)
由于win10 系统原因,个人尝试了很多次,后面的指令都不好操作,于是个人使用的是:
按下win+R 输入cmd 进入cmd指令
进入目标文件夹:
输入 d:
进入python-django里面的scripts文件夹: cd 虚拟环境\python-django\scripts
输入: activate
下一步安装django: pip install django==1.8.2 (如果使用pip install django会默认安装最新版本django,可以根据个人喜好选择版本)
下面新建项目: django-admin startproject testwork (testwork是项目名称)
进入项目文件夹: cd testwork
创建应用: python manage.py startapp test
创建数据库: python manage.py migrate (由于我会使用到MySQL数据库,所以就没有创建数据库)
最后运行,测试是否安装成功 python manage.py runserver
二、创建Git
由于个人提前安装了Git,所以后面的操作在Git里面操作(在cmd里面还没尝试过)
进入项目文件夹 git init
配置个人信息
git config user.name admin
git config user.email ‘111admin@163.com’
提交代码
git add .
git commit -m '项目新建'
git push (在提交的过程中出现了以下错误,说明代码有冲突,但是由于GitHub上面是新建的仓库,所以我最后选择了强制提交,git push -f)
(Username for 'https://github.com': wudaxxm941113
To https://github.com/wudaxxm941113/dailyfresh.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/wudaxxm941113/dailyfresh.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.)
本文总结了在Windows系统中使用Python虚拟环境创建Django项目,并将其提交到GitHub的过程。首先,介绍了如何创建虚拟环境和安装Django,然后详细讲述了初始化Git仓库,配置个人信息,以及在遇到推送冲突时的解决方法。
270

被折叠的 条评论
为什么被折叠?



