1

I have just started learning Django, and I'm facing some problems regarding the 'copy' of the projects. I have two computers and I would like to use both computers for my development. When I was learning PHP (at that time I didnt even know how to use Github), all I had to do was set up a webserver on both computers, and upload the whole files through Google Drive (from one computer) and then download it from the other computer.

However, it seems to me that Django is somewhat different since it is a framework and has a lot of setting ups before starting a project (including virtual environment; I am following a Youtube tutorial and it says that I would be better off if I used virtualenv). I thought it wouldn't work just by downloading the whole project folder to the other computer.

Currently, I have uploaded the whole virtual environment folder on Github.

So, to list my questions,

  1. When downloading it on the other computer, should I setup the virtual environment on that computer and then download the folder?...
  2. Is there any way that I can only sync or commit the files that has been changed in the project automatically? (That is, i have to change many files in django projects(views, urls, settings... etc) but it would be hard to remember all the files that i have changed and then seperately commit those ones)

Any help would be appreciated.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
heesub ahn
  • 27
  • 4

2 Answers2

3

Edit: Consider using pipenv


I suggest that you also install virtualenvwrapper (here). virtualenvwrapper keeps all files except your project at another location so your project directory contains only your files and you can safely use git add --all.

After its installed, do:

$ mkdir my-project; cd my-project
$ mkvirtualenv my-env-name
$ pip install django <more-good-stuff>
$ pip freeze > requirements.txt
$ git init; git add --all; git commit -m "Initial Commit"
... push to github ...

Now go to other machine, and install virtualenv and virtualenvwrapper

$ git clone <url> my-project; cd my-project 
$ mkvirtualenv my-env-name
$ pip install -r requirements.txt
... continue your work, commit and push push and win at life :D
Sourabh
  • 8,243
  • 10
  • 52
  • 98
  • Thanks! but since I am a windows user, it is somewhat hard to use virtualenvwrapper. Anyway, I didn't know what requirements.txt was so I googled it. But I have one more question. Is it possilbe to make requirements.txt file even if I already started my project? What I means is that I have already setup a projects and worked on it, but according to your answer, it seems that I have to do the pip freeze requirements.txt right after the installation. If I can, could you tell me how? – heesub ahn Dec 15 '14 at 11:16
  • It doesn't matter, you can still do `pip freeze > requirements.txt`. If both comp's packages are same then you can skip `pip install -r requirements.txt` step. This file is helpful when someone is setting up a their env for the first time. So, yeah, make that file and udpate is whenever you install some new package. – Sourabh Dec 15 '14 at 14:05
  • Thank you. Could I ask one more question. I have only used github for Windows, and never used git by command line. I tried first time with my git shell, and followed your instruction(along with some help from github guide). It worked fine until the add -all; but when i tried to commit it, nothing happened nor showed up. I got tired of waiting and just pressed enter; then I could write other commands(To me it seemed like 'ok, the process is over, so i can run other commands now.. but I think nothing happend') Is it because there are too many files to commit? Could you explain this briefely? – heesub ahn Dec 16 '14 at 03:00
  • Did you do `git add -all` or `git add --all`? Notice the double dashes `--` – Sourabh Dec 16 '14 at 12:10
  • I did -- all correctly. I got bunch of message lists saying that it was added. But nothing happens after the commit command. Sorry for bothering you.. I'll keep googling – heesub ahn Dec 17 '14 at 00:21
0

you usually don't want to commit everything blindly. It's better if you use git status to see all the files that you changed and then git add those that you want to commit. Once you've verified that you really want to commit all files, you can simply git add --all (more here). And then you git commit.

And, yes, virtualenv is the way to go. You want to create a virtualenv for your project and have all your dependencies in a requirements.txt file. This will allow to have only your source code and no libraries in your git repo, making it much cleaner. This also can allow you to have a set of verified libraries in production, and if you want to try out a new library you can just install it in your local virtualenv. Or even have two virtualenvs and switch, or whatever, and it does not mess your code repo or other machines' installations.

Community
  • 1
  • 1
Martin Massera
  • 1,718
  • 1
  • 21
  • 47