Install Python
- Install Python 3 from www.python.org.
- Run Install Cerltificates.command.
- Install pip and virtualenv
pip3 install --upgrade pip pip3 install virtualenvwrapperPut virtualenvwrapper in .bash_profile:
# Virtualenvwrapper export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper_lazy.sh
Create a Python virtual environment
mkvirtualenv -p /usr/bin/python2 my_proj cd ~/Documents/my_proj setvirtualenvproject-p is optional
Install Visual Studio Code
- Install shell command: Cmd-Shift-p > shell command
- Install Python extension.
Install Postgres
Install Django
pip install Django
Create directory
cd to the parent directory of the directory you wish to place the source files.Create directory for source files with the Django startapp command.
django-admin startproject my_proj cd my_proj setvirtualenvproject
Create app
mkdir my_proj/my_form ./manage.py startapp my_form my_proj/my_form
Configure for VSCode
code .Create a new Django project in VSCode
Initialize git
git init git add .If .pyc files were uninentionally added:
git rm --cached '**.pyc'
Create .gitignore
touch .gitignore code .gitignoreInput:
*.pyc
Static files
STATIC_URL: URL (relative to domain root) to trigger searching for static files.STATICFILES_DIRS: List of directories in which to look for static files when collectstatic is run.
STATIC_ROOT: Django serves files from this directory when run under development mode. Also, collectstatic collects static files here. Upload this to server.
In development: project/static, sibling to project/manage.py
On production: /home/user/domain.com/public/static
settings.py:
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'public/static/')
0 comments:
Post a Comment