The goal of efficiency is more slack.

Sunday, June 16, 2019

Install Django on a development Mac

Notes on installing a Django development environment on a Mac.

Install Python

  • Install Python 3 from www.python.org.
  • Run Install Cerltificates.command.
  • Install pip and virtualenv
pip3 install --upgrade pip
pip3 install virtualenvwrapper
Put 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 .gitignore
Input:
*.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/')   

Related Posts:

  • Django in a subdirectoryHow to serve a Django project as a subdirectory of another Django project's URL. For example, the first Django site is at www.example.com/ and the sec… Read More
  • Logging in DjangoTo log to console in Django. Source: Logging | djangoproject.com settings.py  LOGGING = { 'version': 1, 'disable_existing_loggers'… Read More
  • Django settings in wsgi.pyIn wsgi.py, don't use os.environ.setdefault because another uwsgi vassal may have set the environ already. Set the dictionary directly. os.environ['D… Read More
  • Install Django on a development MacNotes on installing a Django development environment on a Mac. Install Python Install Python 3 from www.python.org. Run Install Cerltificates.comm… Read More
  • Create a new Django project in VSCode Go to user settings (cmd-,): "python.venvPath": "~/.virtualenvs", Quit VSCode. Open a Python file in VSCode. Select virtualenv in bottom ba… Read More

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Powered by Blogger.
Scroll To Top