Visual Studio adds git directory one directory too high - django

For a Django project, I want the git directory in the same directory as the manage.py file. When I create a new python web project in Visual Studio it creates the git directory one directory above where I would put the manage.py file. How do I put the git directory in the right place?
Let's say I create a new project in a folder called "project_dir". The .git directory is placed there. Visual studio creates a sub-folder with the project name (call it project_name) and only allows you to add files and folders within that sub-folder. I want the git data in project_name.
project_dir
├───.git
├───.gitignore
├───project_name.sln
├───project_name
│ ├───manage.py
│ └───project_name.pyproj
When I create a new project I do not have "create new directory for solution" checked. I seems like it's creating a directory for the solution file (.sln) anyway.

Alternative way is you can create the project using command line and run git init command in your project folder. This will initialize the git repo in your project folder.
At the same level with manage.py.

Related

Not able to ignore static files from getting pushed to git in Django project

I had pushed a new Django project BTRE to my git repository. But I can't ignore the static files from pushed to the repository even though I have mentioned the directories in .gitignore file.
-BTRE_Project
|-btre
|-static
This is my .gitignore file:
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
btre/static/
I have tried deleting the repository and pushing again after updating the .gitignore file.
if you want to ignore your static folder and all the files inside static folder than put this in your .gitignore file
static/
this will ignore static directory and files inside that
You can add ignore by adding the folder path in .gitignore file also use git lfs if you want to commit static files.

How can I store my static files to some other github repo?

I am doing a Django Project and I want to store some files (which should be accessible from the project w,r) to some github project as I don't want to store the files and the projects in the same repo.
Any suggestion of doing that?
Let's say, for example, that you want to upload all files with a .css extension to a separate project.
You need to create two files in the root folder of each project. and call them .gitignore
(Don't forget the point at first)
In the repository where you want all files except css files, write in the .gitignore file:
*.css
In the repository where you only want the css files, write in the .gitignore file:
*
!*.css
You will now push the .gitignore files, respectively, to each of the projects you created.

Django file structure w/ venv

I'm fairly new to Django and a bit confused about venvs and the file structure. I'm using VSCode to create all of this.
projectname?/
.vs/
....
.vscode/
....
myproject/ #1
myprojectapps?/
manage.py
myvenv/ #2
myproject/
Include/
Lib/
Scripts/
myprojectapps?/
manage.py
I create a top folder and point VSCode to it. I then create a new venv in this folder (#2).
Where exactly do I then create a new project? Inside my venv or inside my "root" folder?
If I create it in the root folder, will that use my OS Python installation instead of the venv, or is VSCode smart enough to use the venv that I created, if I select it from the dropdown?
Do I create new "apps" in the 'myproject' folders, or in the 'myprojectapps?' folders?
You'r folder structure is ok. you can have myenv in the same root folder.
Note:- mvenv is a place where we will have all thirdparty apps or repositories. So you dont want to have any of your code inside it. infact no code in menv should be under version control/git
So we will not create any django-app inside menv. it can be at same level as menv.
to your .gitignore file please add
.vs
.vsode
myvenv/*
etc
Normally folder structure of django project is something like this ..
projectname/
django-app1/
django-app2/
projectname/ # this is your main folder for settings.
settings.py
urls.py
...
manage.py
etc
so you would create django project you would use django-admin startproject projectname.
And to create an django app from rootfloder you can use python manage.py startapp django-app1
further if you want you can create django app inside a folder called apps/ for that you need to create the folder manually and then run python manage.py startapp django-app1 apps/django-aap1
Insert anything related to vscode inside project directory and open the project at the VScode but don't forget to add .vscode* at .gitignore
projectname?/
myproject/ #1
.vs/
....
.vsode/
....
myprojectapps?/
manage.py
myvenv/ #2
myproject/
Include/
Lib/
Scripts/
myprojectapps?/
manage.py

Virtualenvwrapper not using project_home

I installed virtualenvwrapper on ubuntu. I added the following lines to the top of bashrc file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/myprojects
source /usr/local/bin/virtualenvwrapper.sh
everething works perfect except that when I use django-admin start project command, the project gets created in my home directory not the directory I specified in bashrc file which is myprojects.
shouldn't new projects be created in myprojects folder?
thanks in advance.
I assume you're running django-admin startproject in your home folder? django-admin doesn't know anything about virtualenvwrapper and, unless you explicitly specify a folder, it creates the project in the current folder. See https://docs.djangoproject.com/en/dev/ref/django-admin/#startproject-projectname-destination

Creating a new directory in Heroku

I'm very new to Heroku and I've just pushed my Django app into Heroku. Does anyone know how to create a 'log' directory under '/app'? Is /app the top directory of my app?
Thanks
Is the log directory in your .gitignore file? If /log is an unversioned directory then K Z's answer should help regarding Heroku; unless something else is going on with Heroku and the log directory in your repo.
Regarding committing an empty directory
You cannot commit empty directories to git, but you can add a .gitignore file in a directory that ignores all files inside except itself. This would be as close as you can get to versioning an empty directory as I'm sure you don't want to version control your log files.
Make sure the log directory is not in your main .gitignore file. Then in your log directory create a new .gitignore that contains the following:
# Ignore everything in this directory
*
# Except this file
!.gitignore
You can check out Jamie Flournoy's answer here How can I add an empty directory to a Git repository?
To create a new directory you can simply create one in your local directory (i.e., cd app; mkdir log then commit & push to Heroku.
Whether /app is the top directory or not depends on your directory structure, normally it is the name of the app on Heroku that's set as the top directory. Though, if you are inside your git repository that's used for your Heroku app, you can find the root directory by:
git rev-parse --show-toplevel
which is a git command that tells you the top level directory of this git directory.