Installing PIP
If PIP did not come installed with Python 3, do the following:
- Download
get-pip.py
from: http://pip.readthedocs.org/en/stable/installing.html - If PIP is not Python 3 based, change the program that opens
get-pip.py
into Python33/python.exe - Install PIP using the command line:
python get-pip.py
Virtual Environment
Install and create a virtual environment
C:\>cd PyProjects
C:\PyProjects>pip freeze
C:\PyProjects>pip install virtualenv
C:\PyProjects>python -m pip install --upgrade pip
C:\PyProjects>virtualenv venv
C:\PyProjects>venv\Scripts\activate
Install Django
Activate the new virtual environment and install Django into it
(venv) C:\PyProjects>pip freeze
(venv) C:\PyProjects>cd learning_site
(venv) C:\PyProjects\learning_site>pip install django
(venv) C:\PyProjects\learning_site>python manage.py runserver 0.0.0.0:8000
(venv) C:\PyProjects\learning_site>
(venv) C:\PyProjects>django-admin startproject learning_site
(venv) C:\PyProjects\venv>deactivate
Installing a certain version
pip install django==1.8.1
Start Project
By the way, Django was originally a newspaper company. Django now is a web framework for Python that has really embraced the idea of batteries included.
Unlike some frameworks like Flask, Django tries to give you everything that you’ll need for the basics of your project so you can build as much as possible before you start looking for third party packages.
To get a Django project started, run:
django-admin startproject learning_site
Or
django-admin.py startproject learning_site
We won’t need django-admin again for the rest of our work in this course.
manage.py
This is kind of like Django admin, we’re gonna use this to run commands for our project.
When we need to make a new application, or migrate a database, or anything like that, manage.py is our entry point.
settings.py
This is where all of our settings are.
urls.py
The base URLs for our entire project.
wsgi.py
Controls how our project is served, (e.g. on Heroku, AWS, etc).
Run Project
> cd learning_site
> python manage.py runserver 0.0.0.0:8000
17 unapplied migrations...
First project access: http://localhost:8000
Resolve migration error messages by first killing the server using Ctrl + Break
Then, run migrate
:
python manage.py migrate
Test after migration
> python manage.py runserver 0.0.0.0:8000
You have no error messages now.
Notice that db.sqlite3 is created in your project folder. Django comes with SQLite3.
However, if you want to have serious DB work, you should use a DBMS such as MySQL or Postgres for example.