简体   繁体   English

将Django项目从virtualenv推送到github

[英]Pushing Django project from virtualenv to github

I'm working in virtualenv on a small Django project that needs to be shared on github and then cloned and installed on an Apache server from there. 我正在virtualenv上的一个小型Django项目上工作,该项目需要在github上共享,然后从那里克隆并安装在Apache服务器上。 I have never used virtualenv in conjunction with github before. 我以前从未将virtualenv与github结合使用。 Ordinarily I'd set up the local git repository on the same level as the manage.py file. 通常,我会在与manage.py文件相同的级别上设置本地git存储库。 However, there are several virtualenv directories I don't really want (bin, lib, include etc) on that level along with my needed apps and template directories etc. 但是,在该级别上有几个我真正不需要的virtualenv目录(bin,lib,include等)以及所需的应用程序和模板目录等。

So, what is the way to create a github repository in this case. 那么,在这种情况下,创建github存储库的方法是什么。 Is there a way to be selective and filter out the virtualenv stuff. 有没有一种方法可以选择并过滤出virtualenv的东西。

This is the directory structure I follow - 这是我遵循的目录结构-

/path/to/application/
|-- project
|   |-- projectname
|   |   |-- __init__.py
|   |   |-- local_settings.py
|   |   |-- settings.py
|   |   |-- urls.py
|   |   `-- wsgi.py
|   |-- appone
|   |   |-- admin.py
|   |   |-- __init__.py
|   |   |-- models.py
|   |   |-- tests.py
|   |   `-- views.py
|   `-- manage.py
`-- venv
    |-- bin
    |-- include
    |-- lib
    `-- local

You can easily create a Django project inside a directory called project like this - 您可以像这样在名为project的目录中轻松创建Django项目-

$ django-admin.py startproject projectname project

And initiate virtualenv inside a directory called venv like this - 然后在名为venv的目录中启动virtualenv,如下所示:

$ virtualenv venv

Then you can just go ahead and git init inside /project . 然后,您可以继续在/project里面进行git init This keeps the virtualenv outside the scope of your git repository. 这使virtualenv不在git存储库的范围内。

Otherwise, if you want to stick to your current structure, you can create a .gitignore file and mentione bin , lib , include etc there. 否则,如果您要坚持当前的结构,则可以创建一个.gitignore文件,并在其中提及binlibinclude等。

When working with a virtual environment, the common practice is to include the virtual environment folder in your .gitignore file. 使用虚拟环境时,通常的做法是在.gitignore文件中包括虚拟环境文件夹。 More on how to use this git feature here . 更多关于如何在这里使用git功能的信息

TL;DR: whatever you put in your .gitignore file will get ignored by git. TL; DR:放在.gitignore文件中的任何内容都会被git忽略。 Said file ( .gitignore ) resides in the same directory as your git repository. 所述文件( .gitignore )与git存储库位于同一目录中。

Example of such a file which ignores any compiled source code (.pyc), compressed file (.zip, .rar, .tar), logs and databases (.db, .log, .sql) and virtual environment files (Scripts, Lib, Include) and whole folders (env - name of my virtualenv folder): 此类文件的示例将忽略任何已编译的源代码(.pyc),压缩文件(.zip,.rar,.tar),日志和数据库(.db,.log,.sql)和虚拟环境文件(脚本,Lib) ,包含)和整个文件夹(env-我的virtualenv文件夹的名称):

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Packages #
############
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.db
*.log
*.sql
*.sqlite

# virtualenv generated files #
##############################
Scripts
Lib
Include

# virtualenv folders #
######################
env

阅读有关忽略文件的Github文档-从.gitignore这相当于将.gitignore文件放入您的项目中,并带有与您不希望git管理的文件匹配的模式列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM