1、Github说明
2、创建requirement.txt
- 环境以及安装包十分重要,需要保存或者建立适合的环境
- 导入:进入虚拟环境,然后进入我们需要的目录, 把安装包导入到requirements.txt 文件中
(mysite_env)/mysite/>>pip freeze > ./requirements.txt
- 复原:接收到requirements.txt文件后,把所有的安装包安装到我们的环境中:
(mysite_env)>> pip install -r requirements.txt
3、创建.gitignore文件
创建git的忽略名单,在项目代码中,有些文件不能上传,如密码文件、数据库文件、核心配置文件、临时文件。
安装.gitignore插件:
进入setting-->Plugins-->Browse Repositories-->安装gitignore
在项目根目录下新建.gitignore文件:
.idea
settings.py
db.sqlite3
mysite/__pycache__/
4、特殊文件处理
对于settings.py文件中,SECRET_KEY,数据库的IP/port、用户名和密码,邮件发送端的用户名和密码,这些都是绝对不能泄露的。
复制settings文件,并重命名为settings.example.py文件,放在同一目录里,把敏感信息、密码等修改或删除。
5、添加说明文件和许可文件
README.md
:markdown格式,写说明
进入setting-->Plugins-->Browse Repositories-->安装markdown support
setting-->Editor-->File Types-->Markdown-->看文件后缀
LICENSE
: 许可文件
mysite - User login and register system
Copyright 2017 - yunshu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6、上传代码
- VCS --> Import into Version Control --> Share Project on Github
- 需要安装GIT(官网下载被墙了,另寻它路),并且链接git的安装地址
- git用户(自己的git账户密码)
7、使用Github仓库中的源码
如果你不是从教程的开始一步步地实现整个项目,而是直接使用从Github上copy下来的整个源码,那么你可能需要做一些额外的工作,比如:
- 创建虚拟环境
- 使用pip安装第三方依赖
- 修改settings.example.py文件为settings.py
- 运行migrate命令,创建数据库和数据表
- 运行python manage.py runserver启动服务器
而在Pycharm中运行服务器的话,可能还需要做一些额外的工作,比如:
- 配置解释器
- 配置启动参数