Douglas J. Hajj
0006.0018.2016
Table of Contents
Introduction Install.............................................................4
Python.......................................................................................4
Pip............................................................................................................. 4
virtualenvwrapper..................................................................................... 4
shell_script................................................................................................ 4
Virtual Environments..................................................................4
Django.......................................................................................5
Project....................................................................................................... 5
IDE.............................................................................................5
Pycharm.................................................................................................... 5
Database....................................................................................5
Migrate...................................................................................................... 5
run_server................................................................................................. 5
Install GIT...................................................................................5
Git configuration........................................................................................ 5
Create repository........................................................................6
Collect and add python/pycharm gitignore...............................................6
Add configuration and gitignore chnges to git..........................................6
Check git status......................................................................................... 6
Commit to git.............................................................................6
App............................................................................................7
Add to git................................................................................................... 7
project settings.py..................................................................................... 7
Views.py....................................................................................7
Templates Dir............................................................................................ 7
templates.html.......................................................................................... 7
Urls.py.......................................................................................7
appname views.py.................................................................................... 7
appname.html........................................................................................... 8
appname urls............................................................................................ 8
Refactor.....................................................................................8
Project URLs.............................................................................................. 8
Commit to git............................................................................................ 8
appname Models.py..................................................................................9
Migrations..................................................................................9
Initial Migration......................................................................................... 9
ShowTables................................................................................................ 9
Migrate...................................................................................................... 9
Create SuperUser.......................................................................9
appname admin.py................................................................................... 9
appname views.py modification..............................................................10
appname.html modification....................................................................10
Add migrations to git................................................................10
Chapter - Title....................................................................11
Python.....................................................................................11
SubPython............................................................................................... 11
Introduction Install
This chapter outlines the installation and setup of a simple
django project. Python 2.7.5 is used to keep the initial
documentation concurrent with the instructors code. Python 3
should be used with all future projects.
Python
$python V
Check the python version. At this time, the python version is
2.7.5.
Pip
$sudo easy_install pip
Python package index install. Script found online at
https://bootstrap.pypa.io/get-pip.py . Download script and run
$python get-pip.py Do not install on system python.
virtualenvwrapper
$pip install virtualenvwrapper
Install the virtual environment wrapper.
shell_script
$source /usr/bin/virtualenvwrapper.sh
Install to bash profile following the instructions at this link.
https://virtualenvwrapper.readthedocs.io/en/latest/install.html
Virtual Environments
$mkvirtualenv environmentname-django
Crates the virtual environment and gives it a name. django is
added to show the engine association. To enter an environment
$workon envname. To exit the current environment $deactivate
appname admin.py
from django.contrib import admin
from .modules import modelClass
class BookAdmin(admin.ModelAdmin):
list_display = (title,author,price,stock)
admin.site.register(Book, BookAdmin)
Class grabs varsiables from appname/model.py to display in
django admin backend.
appname views.py modification
from django.shortcuts import render
from .models import Book
def index(request):
return render(request, template.html)
def store(request):
count = Book.objects.all().count()
context = {
count:count,
}
return render(request, store.html, context)
Import the created models and create control definitions. Add
model variables to context and add context to app render
request return.
appname.html modification
<body>
There are {{count}} books in the bookstore.
</body>
Add the created model context variable to the html.
Add migrations to git
$git add migrations/
$git commit am Git commit comment
Add the newly created migrations folder to git and add to repo.
</body>
Activation problem.
registration_form.html modification
<body>
<form method=post action=.>
{% csrf_token %}
{{form.as_p}}
<input type=submit value=Register />
</form>
</body>
Activation form.
registration_complete.html modification
<body>
Thanks for registering! Expect an email.
</body>
Registration completion.
Activation_email.txt modification
Greetings,
You just signed up at {{ site.name }}. Please click the
link to activate it:
http://{{site.domain }}{$ url registration_activate
activation_key %}
This link is valid for {{ registration_days }}. If it wasnt
you that signed up, dont panick. Its safe to ignore this
email.
Outgoing activation email.
Activation_email_subject.txt modification
<body>
Website Name
</body>
Activation problem.
Show migrations to this point
$./manage.py showmigrations
Shows current migration states. $./manage.py migrate to
complete the steps. Git commit.
Chapter - Title
This chapter outlines the setup of a distributed version control
system (DVCS). Install GIT.
Python
$python V
Check the python version. At this time, the python version is
2.7.5.
SubPython
$python V
Check the python version. At this time, the python version is
2.7.5.