.gitignore not ignoring the files Django - python

So I'm testing out Heroku with a dummy app called hellodjango, and pushing everything to git.
Added my .gitignore file (tell me if I'm wrong, I created a text document called django.gitignore, and the contents are 1 line, no spaces, venv*.log*.pot*.pyclocal_settings.py.
Not sure what I'm doing wrong, but here is my directory
hellodjango/
django.gitignore
manage.py
requirements.txt
hellodjango/
__init__.py
__init__.pyc
settings.py
settings.pyc
urls.py
urls.pyc
wsgi.py
wsgi.pyc
venv/
Include/
Lib/
Scripts/
So I don't want to stage any .pyc files or the venv folder.
In my command line, I enter
git init
Initialized empty Git repository in /Users/Chris/hellodjango/.git/
>git add .
>git status
When I enter git status, all of the files in venv and .pyc are staged. Why is .gitignore not working?

The gitignore file needs to be named only .gitignore without a django in front of the dot.
You can find more information about ignoring files and possible patterns supported in the ProGit book on the official website: ProGit Chapter 2-2.

Related

Use included XML files in deployed server

I have xml files that reside in the directory like this
src
|---lib
| |---folder
| | |---XML files
| |---script.py
|---app.py
The app.py file runs the codes in script.py, and in script.py it requires the XML files. When I run the server locally (window) I can just use the relative path "lib\folder\'xml files'". But when I deploy my server to Cloud Run, it says the files don't exist.
I've tried to specify the absolute path by doing this in script.py
package_directory = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(package_directory, "folder\'xml files")
and tried changing all backward dash to forward dash, but the error still occurs.
In the dockerfile, I had this:
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
which I believe to copy everything in the src folder except things specified in .dockerignore, which I had these insides:
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
Because Cloud Run requires a container, a good test for you would be to create the container and run it locally. I suspect that it's your container that's incorrect rather than Cloud Run.
I created the following repro of your code:
.
├── app.py
├── Dockerfile
└── lib
├── folder
│   └── XML files
│   └── test
├── __init__.py
└── script.py
app.py:
from lib import script
script.foo()
script.py:
import os
def foo():
package_directory = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(package_directory, "folder/XML files")
for f in os.listdir(path):
if os.path.isfile(os.path.join(path,f)):
print(f)
Dockerfile:
FROM docker.io/python:3.9.9
ENV APP_HOME /app
WORKDIR ${APP_HOME}
COPY . ./
ENTRYPOINT ["python","app.py"]
And, when I build|run the container, it correctly reports test:
Q="70734734"
podman build \
--tag=${Q} \
--file=./Dockerfile \
.
podman run \
--interactive --tty \
localhost/${Q}
I'm confident that, if I were to push it to Cloud Run, it would work correctly there too.
NOTE
Try to avoid spaces in directory names; os.path.join accommodates spaces
You describe XML files but your code references xml files
You don't include a full repro of your issue making it more difficult to help you

Django: Startapp Generated files into existing project folder

I want to place django app files into generated Django project folder .
MyProject/
MyProject/
settings.py
urls.py
here i want to insert my Django app files like, views.py, admin.py, models.py etc into same MyProject folder itself. we can do the same by copy paste after app was created. but i want to know is their any magic we can achieve the same while executing this command?
django-admin startapp MyApp <directory>
I dont want to create Myapp folder instead Myapp/* should be move onto Myproject/ itself. without doing copy paste thing.
so finally i want my Project folder should be like this,
MyProject/
MyProject/
admin.py
models.py
settings.py
urls.py
views.py
command to run from same direcory. If you change directory then change in path also:
django-admin startproject myproject
django-admin startapp myapp myproject\myproject\
command sample:
E:\write here>django-admin startproject myproject
E:\write here>dir myproject\myproject
Volume in drive E has no label.
Volume Serial Number is ****-****
Directory of E:\write here\myproject\myproject
03-06-2017 11.53 AM <DIR> .
03-06-2017 11.53 AM <DIR> ..
03-06-2017 11.53 AM 3,103 settings.py
03-06-2017 11.53 AM 766 urls.py
03-06-2017 11.53 AM 396 wsgi.py
03-06-2017 11.53 AM 0 __init__.py
4 File(s) 4,265 bytes
2 Dir(s) 80,954,753,024 bytes free
E:\write here>django-admin startapp myapp myproject\myproject\
CommandError: E:\write here\myproject\myproject\__init__.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
don't worry about above error because it is just notifying you that __init__.py is not to be overwrite.

I cannot ignore pycache and db.sqlite on Django even though it refers them at .gitignore

I'd like to ignore the changes of pycache and db.sqlite of Django project. I refer them at .gitignore,however git catches the variation of them. Could you tell me what is problem if you know it?
I attached my .gitignore at the end of sentence.
.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
media/
settings.py
.idea/
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
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
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
.venv/
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# Database stuff
*.sqlite3
migrations/
db.sqlite3
# Atom config file
.editorconfig
# Other unwanted stuff
.idea
.DS_Store
.DS_STORE
As follows, I've solved the problem.
git rm -r --cached . # will delete whole git history, use with caution
git add .
git commit -m
git push ~
As an alternative to git rm -r --cached . in the #lalala's answer, you can target the files you actually want to delete from the cache using git rm --cached <filename>.
This is generally more desirable since it leaves the other files untouched. You may use metacharacters like *.sqlite in place of <filename> to target even more files.

foreman start error, Procfile does not exist

Directory Contents
sid#midnight:~/kuma$ ls
admin_dashboard.py requirements
celery.py scripts
configs settings_local.py
contribute.json settings.py
CONTRIBUTING.md settings_test.py
docs settings_travis.py
etc templates
kuma tests
kumascript tox.ini
kumascript_settings_local.json urls.py
kumascript_settings_local.json-dist vagrantconfig_local.yaml
LICENSE vagrantconfig_local.yaml-dist
manage.py vagrantconfig.yaml
media Vagrantfile
migrations vendor
Procfile webroot
puppet wsgi
README.rst
Then I did vagrant ssh
Which succeeded with Last Login:...
Then I did foreman start, which gave
vagrant#developer-local:~$ foreman start
ERROR: Procfile does not exist.
What am I doing wrong?? I'm a beginner to this stuff, please go easy on me. Thank you.

Pinax Structure

I have just installed the Pinax but i'm very confused now.
in my structre
i have two directories
mysite and mysite-env
I dont why i have two directories. I just followed the installitation directions
in mysite,
<project-root>
apps/
__init__.py
deploy/
__init__.py
fcgi.py
wsgi.py
fixtures/
initial_data.json
locale/
...
requirements/
base.txt
project.txt
sitemedia/static // I move static file from mysite-env to here
...
templates/
_footer.html
homepage.html
site_base.html
__init__.py
manage.py
settings.py
urls.py
However,
default index page is in mysite-env/lib/python2.6/site-packages/pinax_theme_bootstrap/templates/banner_base.html
Should i manage my site from mysite ?
Pinax uses virtualenv to prevent messing up your local python libs by your project dependency.
So, launch the site with $ source mysite-env/bin/activate it will be fine. If you really hate mysite-env, just skip the virtualenv part.

Categories