Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what should be in gitignore, and how do I put env folder to gitignore and is my folder structure correct?

Tags:

python

django

I'm about to deploy my project. and I see I did't create gitignore before I uploaded to bitbucket. Now I created gitignore, and wasn't sure what to add so I googled and found Recommended .gitignore file for Python projects? according to this, this is the best one

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/ 

but I don't even know I have those things in my project. Also I saw I'm suppose to ignore virtualenv folder too. I have

project
----project(inside here my files exist)
----env
----static
----.gitignore
----Read_Me.txt
----requirements.txt
like image 438
em four Avatar asked Mar 16 '16 10:03

em four


2 Answers

Your env folder should be in the gitignore, but it doesn't have to be in your project folder. You can put everything you want in your gitignore.

For example :

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
db.sqlite3
migrations/
media/
settings.py
# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

Your folder structure seems good, I would add some directories in it, to optimize your code and general architecture, mine looks like that, and that's pretty awesome, but you can do what you want for all your project :

project/
---project/
---app1/
---app2/
------migrations/
------url/
---------__init__.py
---------url1.py
---------url2.py
------views/
---------__init__.py
---------view1.py
---------view2.py
------forms/
---------__init__.py
---------form1.py
------models/
---------__init__.py
---------model1.py
---------model2.py
---app3/
---static/
---templates/
------app1/
------app2/
---------view1/
-------------home.html
---------layout.html
------app3/
---templatetags/
---manage.py

This project structure allows you to separate the different templates of all your app, better to modify them quickly and easily. It allows you to have a refactored code inside each app, it permits to prevent future code error (4000 codes lines in files comes really quickly so be careful!).

You also can have separate folders for all your statics and templatetags, so you can use it everywhere in your templates, pretty awesome !

Remember, you can do everything you want with your folder structure, the best you can do is the best that fits you :)

Hope it helps !

like image 145
Bloodbee Avatar answered Sep 28 '22 13:09

Bloodbee


Your virtualenv folder can be completely outside your tracked folder. Just add requirements.txt in it.

like image 43
loutre Avatar answered Sep 28 '22 13:09

loutre