By Sheldon L | Published at 2019-11-22 | Updated at 2019-11-29 |
Django
Flask
React
Angular
pip install pipenv
# To remove pipenv
# in the root of the env file (always have a Pipfile in it)
# the prompt should be: `(env_name)name@host:~/..$`
# to remove
pipenv --rm
rm Pipfil*
rm -rf <Project>
python3 -m venv venv
venv/bin/activate
# create and activate environment
conda search "^python$"
conda create --name dj_py38 python=3.8
source activate dj_py38
# check environment
python --virsion
conda info --envs
export all_proxy=""
pip install pysocks
export all_proxy="socks5://127.0.0.1:1080"
.ignore
plugin and create .gitignore
in settings.python3 --version
mkvirtualenv django3 --python=/usr/bin/python3.7
workon django3
pip install django
python3 -m django --version
cd ~/djProjects
django-admin startproject mysite
vim ~/djProjects/mysite/mysite/settings.py
"""/ upate ALLOWED_HOSTS
ALLOWED_HOSTS = ['*']
"""
cd ~/djProjects/mysite
python manage.py check
web
tabadd a new web application
, manually
, get settings done
/home/SheldonLee/djProjects/mysite
/home/SheldonLee/djProjects/mysite
/home/SheldonLee/.virtualenvs/django3
/var/www/..._..._..._com_wsgi.py
like this:import os
import sys
path = os.path.expanduser('~/djProjects/mysite')
if path not in sys.path:
sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
click reload ....pythonanywhere.com
click my url sheldonlee.pythonanywhere.com
cd ~/djProjects
git init
# after create an empty ropo on github:
git remote add origin git@github.com:sheldonldev/djProjects_onPyAnyw.git
git add .
git commit -a
ssh-keygen -t rsa -C my_email@domain.com
cat ~/.ssh/id_rsa.pub
git push --set-upstream origin master
cd $hub/mysite_test
git clone git@github.com:sheldonldev/djProjects_onPyAnyw.git
export all_proxy=socks5://127.0.0.1:1080
conda create --name dj_py37 python=3.7
conda activate dj_py37
export all_proxy=""
pip install pysocks
export all_proxy=socks5://127.0.0.1:1080
pip install django
pyCharm
:
dj_py37
;django support
in language and framework
;New
- .ignor file
- .gitignore
;pip freeze -> requirements.txt
git add .
git commit -a
git push
syncro github to PythonAnywhere
cd ~/djProject
git pull
workon django3
pip install requirements.txt
git stash
git pull
git stash apply
PostgreSQL packages for Debian and Ubuntu
sudo apt-get install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
# uninstall
sudo apt-get -y purge postgresql-client-common pgadmin4
OR Install PgAdmin4 in a virtual env, and install postgresql in UBUNTU (Recommended)
# install
build-essential libssl-dev libffi-dev libgmp3-dev
virtualenv python-pip libpq-dev python-dev
# for install psycopg2 later
sudo apt-get install libpq-dev
# download package from https://www.postgresql.org/ftp/pgadmin/pgadmin4/v4.15/pip/
# use a virtual python env to install
pip install pgadmin4-2.1-py2.py3-none-any.whl
# create and edit `config_local.py`
touch <env>/lib/python3.7/site-packets/pgadmin4/config_local.py
vim <env>/lib/python3.7/site-packets/pgadmin4/config_local.py
# add following content:
"""
import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
SERVER_MODE = False
"""
# then
pip install psycopg2 # or conda install
python <env>/lib/python<version>/site-packages/pgadmin4/pgAdmin4.py
# install any moduel need to be imported
# see 127.0.0.1:5050, PGADMIN INSTALLATION DONE!
# install postgres package for PostgreSQL and contrib package for taking additional functionalities related to PostgreSQL
sudo apt-GET install postgresql postgresql-contrib
# create the username and password for PostgreSQL database
sudo -u postgres psql postgres
""" in postgres
# \password postgres
<--! to quit -->
# \q
"""
How to Deploy a Django App to Heroku in 2018… The Easy Way
pip install gunicorn
pip install django-heroku
# no need in virtual env
sudo snap install heroku --classic
pip freeze > requirements.txt
# create a heroku account
# set ssh key
# check API key
# login to your heroku
heroku login
# create new app if one doesn't yet exist
heroku create
# log in to the app in heroku to set other stuff
# create a new postgres database for your app
heroku addons:create heroku-postgresql:hobby-dev
git add .
git commit -m "Ready to heroku this sucker in the face."
git push origen master
# migrate your database to the heroku app
python manage.py makemigrations
python manage.py migrate
# before you do this, make sure to add your SECRET_KEY to your env variables in your heroku app settings
git add .
git commit -m "Ready to heroku this sucker in the face."
git push heroku master
[Heroku | Python Documentation](https://devcenter.heroku.com/articles/deploying-python) |