Requirement.txt
===========
Django==1.8.3
django-nose==1.4.1
nose==1.3.7
requests==2.7.0
wsgiref==0.1.2
============
This tutorial assumes very little, so we’ll cover the following concepts throughout:
Where
Under the hood, Django will use these models to create Structured Query Language, which in turn will store these models into a SQL database (MySQL, SQLite3, PostgreSQL). Using these methods, we won’t have to write our own database logic using SQL.
In Django, views generally consist of a combination of templates, the URL dispatcher, and a
JSON is used for websites such as Twitter, Facebook and Flickr to update asynchonously (without page reloads), and is the core in developing full-stack JavaScript applications. A sample snippet of JSON from Facebook can be seen below:
With that all said and done, let’s get into the development of the application.
Where demonstration is the name you choose for your own project.
Breaking down each of these files:
Let’s go ahead and fix that. You can stop the server using
This command will build all of the default database tables that Django needs for built-in services such as user authentication. For now, this isn’t too relevant to us.
Navigate to http://127.0.0.1:8000/ and you’ll be greeted with the nice shiny page:
Great! You’ve run your first Django web application. However, as the message states, we haven’t configured any URLs yet. We’ll get to that shortly, but for now let’s actually create our application.
Where app is the name you’ve chosen for this
specific application. It is within this folder that we’ll be writing a
bulk of our code in, with the exception of modifying the base
Breaking down these files:
This will configure our paths for our Static files (CSS, JavaScript, images, etc) as well as the path to our template files.
Lastly, we’ll need to register your application (named app) under the Installed Apps section:
We’ll now move onto configuring a basic URL which will print out “Hello World”.
Now, our URLs may be accessed as
And we’ll add the following content:
We’ve successfully mapped the
If we navigate to http://127.0.0.1:8000/app/test/, you should be greeted with the text “My second view!”.
Alright, you should be getting the hang of it now. We’ve been making some toy views, but how about we move onto displaying some meaningful data to the user? In particular, we’ll display the Github profile information for a given user.
Where :user is the name of the Github user you’d
like to query profile information about. Before we display this data in
Django, I highly encourage you to open up a terminal shell and try the
following:
You should be presented with the following data:
As easy as that, we performed an HTTP GET request to the API endpoint
and received JSON back. Let’s go ahead and wire this up in Django. As
an exercise, try to create the urls and view method yourself before
moving forward.
Going forward, we’ll need a method to load json strings easily. Be sure to
Navigate to http://127.0.0.1:8000/app/profile and you’ll be greeted with the following response:
At the moment, the output is kind of messy. Let’s update our view
Which will return the new response:
As of now, we’ve covered a bunch of topics in only < 30 lines of Python. Let’s take a moment to recap what we’ve learned:
In this step, I’ll walk you through downloading Twitter bootstrap as well as generating your own
In the same directory as
Anytime we run
This will download Twitter Bootstrap into our project directory, as specified within our
Within our templates/app folder, we’ll create our
Most of this is just Bootstrap classes for styling, but there is one important syntax to observe here:
This syntax allows us to iterate over a data structure using a
In this case,
Awesome, we’ve got a nice layout. As of now, our view method is essentially hardcoded - we can’t query any particular user’s Github information. We’ll need to come up with a way to ask the user for an input, and to do this we’ll move onto forms.
To begin, we’ll go ahead and build our form within our
Let’s break this down in pieces:
This is simply a CSS class which we’ll use to style our form with.
Here we are creating our
We’re also specifying the type of HTTP method this form will perform after submission:
Once we submit our form, it will perform an HTTP post request which
will send the input that the user inputs as parameters to the following
url:
Where
The
Next, we look at our input field:
Which has the following attributes:
The most important attribute to pay attention to is
Where we provide attributes specifying the bootstrap styling class
Putting it all together:
Next, we’ll learn how to capture these POST parameters in our views and use them.
Most of the code is exactly the same, but we’ll break down the new additions in pieces:
If our
Here we actually access our POST parameters. From our form, we know that our single field had an attribute of
And the rest is the same as before. Using the new parameterized url,
it will grab the Github profile information for a given username as
passed through our form. Go ahead and try putting in various usernames
of your friends on Github!
I hope this guide has been helpful for beginners (and possibly non-beginners). I’ll be exploring more complicated tech stacks using Django + ReactJS in the near future, so stay tuned for more tutorials.
Thanks for reading.
===================
================================
terminal
===============================
erp@erp-OptiPlex-330:~$ mkdir boot
erp@erp-OptiPlex-330:~$ cd boot
erp@erp-OptiPlex-330:~/boot$ virtualenv boot
New python executable in boot/bin/python
Installing setuptools, pip, wheel...done.
erp@erp-OptiPlex-330:~/boot$ ls
boot
erp@erp-OptiPlex-330:~/boot$ source /boot/bin/activate
bash: /boot/bin/activate: No such file or directory
erp@erp-OptiPlex-330:~/boot$ ls
boot
erp@erp-OptiPlex-330:~/boot$ cd boot
erp@erp-OptiPlex-330:~/boot/boot$ ls
bin django include lib local
erp@erp-OptiPlex-330:~/boot/boot$ source ./bin/activate
(boot)erp@erp-OptiPlex-330:~/boot/boot$ ls
bin django include lib local
(boot)erp@erp-OptiPlex-330:~/boot/boot$ cd django
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ ls
app bower.json demonstration manage.py README.md requirements.txt
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ pip install -r requirements.txt
/home/erp/boot/boot/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting Django==1.8.3 (from -r requirements.txt (line 1))
/home/erp/boot/boot/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Using cached Django-1.8.3-py2.py3-none-any.whl
Collecting django-nose==1.4.1 (from -r requirements.txt (line 2))
Downloading django_nose-1.4.1-py2-none-any.whl
Collecting nose==1.3.7 (from -r requirements.txt (line 3))
Downloading nose-1.3.7-py2-none-any.whl (154kB)
100% |████████████████████████████████| 155kB 1.6MB/s
Collecting requests==2.7.0 (from -r requirements.txt (line 4))
Downloading requests-2.7.0-py2.py3-none-any.whl (470kB)
100% |████████████████████████████████| 471kB 564kB/s
Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt (line 5))
Installing collected packages: Django, nose, django-nose, requests
Successfully installed Django-1.8.3 django-nose-1.4.1 nose-1.3.7 requests-2.7.0
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py syncdb
/home/erp/boot/boot/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages, django_nose
Apply all migrations: admin, contenttypes, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'erp'): erp
Email address: erp@gmail.com
Password:
Password (again):
Superuser created successfully.
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 01, 2015 - 12:29:57
Django version 1.8.3, using settings 'demonstration.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
pip install -r requirements.txt[01/Sep/2015 12:30:02]"GET / HTTP/1.1" 404 2015
[01/Sep/2015 12:30:06]"GET /app HTTP/1.1" 301 0
[01/Sep/2015 12:30:06]"GET /app/ HTTP/1.1" 200 12
[01/Sep/2015 12:30:12]"GET /admin HTTP/1.1" 301 0
[01/Sep/2015 12:30:12]"GET /admin/ HTTP/1.1" 302 0
[01/Sep/2015 12:30:12]"GET /admin/login/?next=/admin/ HTTP/1.1" 200 1915
[01/Sep/2015 12:30:12]"GET /static/admin/css/login.css HTTP/1.1" 200 940
[01/Sep/2015 12:30:12]"GET /static/admin/css/base.css HTTP/1.1" 200 14049
[01/Sep/2015 12:30:12]"GET /static/admin/img/nav-bg.gif HTTP/1.1" 200 265
[01/Sep/2015 12:30:16]"POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[01/Sep/2015 12:30:16]"GET /admin/ HTTP/1.1" 200 3018
[01/Sep/2015 12:30:16]"GET /static/admin/css/dashboard.css HTTP/1.1" 200 434
[01/Sep/2015 12:30:16]"GET /static/admin/img/default-bg.gif HTTP/1.1" 200 836
[01/Sep/2015 12:30:16]"GET /static/admin/img/icon_changelink.gif HTTP/1.1" 200 119
[01/Sep/2015 12:30:16]"GET /static/admin/img/icon_addlink.gif HTTP/1.1" 200 119
[01/Sep/2015 12:30:19]"GET /admin/auth/user/ HTTP/1.1" 200 6598
[01/Sep/2015 12:30:19]"GET /static/admin/css/changelists.css HTTP/1.1" 200 5254
[01/Sep/2015 12:30:19]"GET /static/admin/js/jquery.init.js HTTP/1.1" 200 326
[01/Sep/2015 12:30:19]"GET /static/admin/js/actions.js HTTP/1.1" 200 4910
[01/Sep/2015 12:30:19]"GET /static/admin/js/jquery.js HTTP/1.1" 200 284184
[01/Sep/2015 12:30:19]"GET /static/admin/js/core.js HTTP/1.1" 200 7522
[01/Sep/2015 12:30:19]"GET /static/admin/js/admin/RelatedObjectLookups.js HTTP/1.1" 200 4464
[01/Sep/2015 12:30:19]"GET /admin/jsi18n/ HTTP/1.1" 200 2372
[01/Sep/2015 12:30:19]"GET /static/admin/img/icon-yes.gif HTTP/1.1" 200 299
[01/Sep/2015 12:30:19]"GET /static/admin/img/changelist-bg.gif HTTP/1.1" 200 50
[01/Sep/2015 12:30:19]"GET /static/admin/img/icon_searchbox.png HTTP/1.1" 200 368
[01/Sep/2015 12:30:19]"GET /static/admin/img/tooltag-add.png HTTP/1.1" 200 119
[01/Sep/2015 12:30:19]"GET /static/admin/img/nav-bg-reverse.gif HTTP/1.1" 200 178
[01/Sep/2015 12:30:19]"GET /static/admin/img/nav-bg-selected.gif HTTP/1.1" 200 265
[01/Sep/2015 12:30:19]"GET /static/admin/img/sorting-icons.gif HTTP/1.1" 200 369
[01/Sep/2015 12:30:22]"GET /admin/auth/group/ HTTP/1.1" 200 3590
[01/Sep/2015 12:30:22]"GET /admin/jsi18n/ HTTP/1.1" 200 2372
[01/Sep/2015 12:30:22]"GET /static/admin/css/base.css HTTP/1.1" 304 0
[01/Sep/2015 12:30:23]"GET /static/admin/img/nav-bg.gif HTTP/1.1" 304 0
^C(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ npm install -g bower
The program 'npm' is currently not installed. You can install it by typing:
sudo apt-get install npm
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ sudo apt-get install npm
[sudo] password for erp:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
account-plugin-windows-live libupstart1 linux-headers-3.16.0-30
linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic
linux-image-extra-3.16.0-30-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libssl-dev
libssl-doc libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-archy
node-async node-block-stream node-combined-stream node-cookie-jar
node-delayed-stream node-forever-agent node-form-data node-fstream
node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream
node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once
node-osenv node-qs node-read node-read-package-json node-request node-retry
node-rimraf node-semver node-sha node-sigmund node-slide node-tar
node-tunnel-agent node-which nodejs nodejs-dev zlib1g-dev
Suggested packages:
apache2 lighttpd httpd node-hawk node-aws-sign node-oauth-sign
node-http-signature
The following NEW packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libssl-dev
libssl-doc libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-archy
node-async node-block-stream node-combined-stream node-cookie-jar
node-delayed-stream node-forever-agent node-form-data node-fstream
node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream
node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once
node-osenv node-qs node-read node-read-package-json node-request node-retry
node-rimraf node-semver node-sha node-sigmund node-slide node-tar
node-tunnel-agent node-which nodejs nodejs-dev npm zlib1g-dev
0 upgraded, 57 newly installed, 0 to remove and 13 not upgraded.
Need to get 5,378 kB of archives.
After this operation, 20.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/main libc-ares2 i386 1.10.0-2 [38.3 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu/ trusty/universe gyp all 0.1~svn1729-3ubuntu1 [201 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ trusty/main javascript-common all 11 [6,066 B]
Get:4 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libjs-node-uuid all 1.4.0-1 [11.1 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu/ trusty/main zlib1g-dev i386 1:1.2.8.dfsg-1ubuntu1 [181 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main libssl-dev i386 1.0.1f-1ubuntu2.15 [989 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main libssl-doc all 1.0.1f-1ubuntu2.15 [966 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libv8-3.14.5 i386 3.14.5.8-5ubuntu2 [1,192 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libv8-3.14-dev i386 3.14.5.8-5ubuntu2 [57.6 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu/ trusty/universe nodejs i386 0.10.25~dfsg2-2ubuntu1 [689 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-async all 0.2.5-1 [17.7 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-node-uuid all 1.4.0-1 [2,530 B]
Get:13 http://in.archive.ubuntu.com/ubuntu/ trusty/main libc-ares-dev i386 1.10.0-2 [104 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-abbrev all 1.0.4-2 [3,814 B]
Get:15 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-ansi all 0.2.1-1 [8,692 B]
Get:16 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-archy all 0.0.2-1 [3,660 B]
Get:17 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-inherits all 2.0.0-1 [3,090 B]
Get:18 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-block-stream all 0.0.7-1 [4,832 B]
Get:19 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-delayed-stream all 0.0.5-1 [4,750 B]
Get:20 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-combined-stream all 0.0.4-1 [4,686 B]
Get:21 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-cookie-jar all 0.3.1-1 [3,746 B]
Get:22 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-forever-agent all 0.5.1-1 [3,194 B]
Get:23 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mime all 1.2.11-1 [20.2 kB]
Get:24 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-form-data all 0.1.0-1 [6,412 B]
Get:25 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-rimraf all 2.2.2-2 [5,392 B]
Get:26 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mkdirp all 0.3.5-1 [4,146 B]
Get:27 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-graceful-fs all 2.0.0-2 [6,718 B]
Get:28 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-fstream all 0.1.24-1 [19.5 kB]
Get:29 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-lru-cache all 2.3.1-1 [5,674 B]
Get:30 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-sigmund all 1.0.0-1 [3,818 B]
Get:31 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-minimatch all 0.2.12-1 [14.9 kB]
Get:32 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-fstream-ignore all 0.0.6-2 [5,586 B]
Get:33 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-github-url-from-git all 1.1.1-1 [3,138 B]
Get:34 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-glob all 3.2.6-1 [13.7 kB]
Get:35 http://in.archive.ubuntu.com/ubuntu/ trusty/universe nodejs-dev i386 0.10.25~dfsg2-2ubuntu1 [168 kB]
Get:36 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-nopt all 2.1.2-1 [11.8 kB]
Get:37 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-npmlog all 0.0.4-1 [5,844 B]
Get:38 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-osenv all 0.0.3-1 [3,810 B]
Get:39 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-tunnel-agent all 0.3.1-1 [4,018 B]
Get:40 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-json-stringify-safe all 5.0.0-1 [3,544 B]
Get:41 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-qs all 0.6.5-1 [5,876 B]
Get:42 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-request all 2.26.1-1 [14.5 kB]
Get:43 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-semver all 2.1.0-2 [16.2 kB]
Get:44 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-tar all 0.1.18-1 [18.3 kB]
Get:45 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-which all 1.0.5-2 [3,678 B]
Get:46 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-gyp all 0.10.10-2 [22.6 kB]
Get:47 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-ini all 1.1.0-1 [4,770 B]
Get:48 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-lockfile all 0.4.1-1 [5,450 B]
Get:49 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mute-stream all 0.0.3-1 [3,738 B]
Get:50 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-normalize-package-data all 0.2.2-1 [9,286 B]
Get:51 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-once all 1.1.1-1 [2,608 B]
Get:52 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-read all 1.0.4-1 [4,282 B]
Get:53 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-read-package-json all 1.1.3-1 [7,762 B]
Get:54 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-retry all 0.6.0-1 [6,172 B]
Get:55 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-sha all 1.2.3-1 [4,272 B]
Get:56 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-slide all 1.1.4-1 [6,118 B]
Get:57 http://in.archive.ubuntu.com/ubuntu/ trusty/universe npm all 1.3.10~dfsg-1 [442 kB]
Fetched 5,378 kB in 16s (320 kB/s)
Extracting templates from packages: 100%
Selecting previously unselected package libc-ares2:i386.
(Reading database ... 243598 files and directories currently installed.)
Preparing to unpack .../libc-ares2_1.10.0-2_i386.deb ...
Unpacking libc-ares2:i386 (1.10.0-2) ...
Selecting previously unselected package gyp.
Preparing to unpack .../gyp_0.1~svn1729-3ubuntu1_all.deb ...
Unpacking gyp (0.1~svn1729-3ubuntu1) ...
Selecting previously unselected package javascript-common.
Preparing to unpack .../javascript-common_11_all.deb ...
Unpacking javascript-common (11) ...
Selecting previously unselected package libjs-node-uuid.
Preparing to unpack .../libjs-node-uuid_1.4.0-1_all.deb ...
Unpacking libjs-node-uuid (1.4.0-1) ...
Selecting previously unselected package zlib1g-dev:i386.
Preparing to unpack .../zlib1g-dev_1%3a1.2.8.dfsg-1ubuntu1_i386.deb ...
Unpacking zlib1g-dev:i386 (1:1.2.8.dfsg-1ubuntu1) ...
Selecting previously unselected package libssl-dev:i386.
Preparing to unpack .../libssl-dev_1.0.1f-1ubuntu2.15_i386.deb ...
Unpacking libssl-dev:i386 (1.0.1f-1ubuntu2.15) ...
Selecting previously unselected package libssl-doc.
Preparing to unpack .../libssl-doc_1.0.1f-1ubuntu2.15_all.deb ...
Unpacking libssl-doc (1.0.1f-1ubuntu2.15) ...
Selecting previously unselected package libv8-3.14.5.
Preparing to unpack .../libv8-3.14.5_3.14.5.8-5ubuntu2_i386.deb ...
Unpacking libv8-3.14.5 (3.14.5.8-5ubuntu2) ...
Selecting previously unselected package libv8-3.14-dev.
Preparing to unpack .../libv8-3.14-dev_3.14.5.8-5ubuntu2_i386.deb ...
Unpacking libv8-3.14-dev (3.14.5.8-5ubuntu2) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_0.10.25~dfsg2-2ubuntu1_i386.deb ...
Unpacking nodejs (0.10.25~dfsg2-2ubuntu1) ...
Selecting previously unselected package node-async.
Preparing to unpack .../node-async_0.2.5-1_all.deb ...
Unpacking node-async (0.2.5-1) ...
Selecting previously unselected package node-node-uuid.
Preparing to unpack .../node-node-uuid_1.4.0-1_all.deb ...
Unpacking node-node-uuid (1.4.0-1) ...
Selecting previously unselected package libc-ares-dev:i386.
Preparing to unpack .../libc-ares-dev_1.10.0-2_i386.deb ...
Unpacking libc-ares-dev:i386 (1.10.0-2) ...
Selecting previously unselected package node-abbrev.
Preparing to unpack .../node-abbrev_1.0.4-2_all.deb ...
Unpacking node-abbrev (1.0.4-2) ...
Selecting previously unselected package node-ansi.
Preparing to unpack .../node-ansi_0.2.1-1_all.deb ...
Unpacking node-ansi (0.2.1-1) ...
Selecting previously unselected package node-archy.
Preparing to unpack .../node-archy_0.0.2-1_all.deb ...
Unpacking node-archy (0.0.2-1) ...
Selecting previously unselected package node-inherits.
Preparing to unpack .../node-inherits_2.0.0-1_all.deb ...
Unpacking node-inherits (2.0.0-1) ...
Selecting previously unselected package node-block-stream.
Preparing to unpack .../node-block-stream_0.0.7-1_all.deb ...
Unpacking node-block-stream (0.0.7-1) ...
Selecting previously unselected package node-delayed-stream.
Preparing to unpack .../node-delayed-stream_0.0.5-1_all.deb ...
Unpacking node-delayed-stream (0.0.5-1) ...
Selecting previously unselected package node-combined-stream.
Preparing to unpack .../node-combined-stream_0.0.4-1_all.deb ...
Unpacking node-combined-stream (0.0.4-1) ...
Selecting previously unselected package node-cookie-jar.
Preparing to unpack .../node-cookie-jar_0.3.1-1_all.deb ...
Unpacking node-cookie-jar (0.3.1-1) ...
Selecting previously unselected package node-forever-agent.
Preparing to unpack .../node-forever-agent_0.5.1-1_all.deb ...
Unpacking node-forever-agent (0.5.1-1) ...
Selecting previously unselected package node-mime.
Preparing to unpack .../node-mime_1.2.11-1_all.deb ...
Unpacking node-mime (1.2.11-1) ...
Selecting previously unselected package node-form-data.
Preparing to unpack .../node-form-data_0.1.0-1_all.deb ...
Unpacking node-form-data (0.1.0-1) ...
Selecting previously unselected package node-rimraf.
Preparing to unpack .../node-rimraf_2.2.2-2_all.deb ...
Unpacking node-rimraf (2.2.2-2) ...
Selecting previously unselected package node-mkdirp.
Preparing to unpack .../node-mkdirp_0.3.5-1_all.deb ...
Unpacking node-mkdirp (0.3.5-1) ...
Selecting previously unselected package node-graceful-fs.
Preparing to unpack .../node-graceful-fs_2.0.0-2_all.deb ...
Unpacking node-graceful-fs (2.0.0-2) ...
Selecting previously unselected package node-fstream.
Preparing to unpack .../node-fstream_0.1.24-1_all.deb ...
Unpacking node-fstream (0.1.24-1) ...
Selecting previously unselected package node-lru-cache.
Preparing to unpack .../node-lru-cache_2.3.1-1_all.deb ...
Unpacking node-lru-cache (2.3.1-1) ...
Selecting previously unselected package node-sigmund.
Preparing to unpack .../node-sigmund_1.0.0-1_all.deb ...
Unpacking node-sigmund (1.0.0-1) ...
Selecting previously unselected package node-minimatch.
Preparing to unpack .../node-minimatch_0.2.12-1_all.deb ...
Unpacking node-minimatch (0.2.12-1) ...
Selecting previously unselected package node-fstream-ignore.
Preparing to unpack .../node-fstream-ignore_0.0.6-2_all.deb ...
Unpacking node-fstream-ignore (0.0.6-2) ...
Selecting previously unselected package node-github-url-from-git.
Preparing to unpack .../node-github-url-from-git_1.1.1-1_all.deb ...
Unpacking node-github-url-from-git (1.1.1-1) ...
Selecting previously unselected package node-glob.
Preparing to unpack .../node-glob_3.2.6-1_all.deb ...
Unpacking node-glob (3.2.6-1) ...
Selecting previously unselected package nodejs-dev.
Preparing to unpack .../nodejs-dev_0.10.25~dfsg2-2ubuntu1_i386.deb ...
Unpacking nodejs-dev (0.10.25~dfsg2-2ubuntu1) ...
Selecting previously unselected package node-nopt.
Preparing to unpack .../node-nopt_2.1.2-1_all.deb ...
Unpacking node-nopt (2.1.2-1) ...
Selecting previously unselected package node-npmlog.
Preparing to unpack .../node-npmlog_0.0.4-1_all.deb ...
Unpacking node-npmlog (0.0.4-1) ...
Selecting previously unselected package node-osenv.
Preparing to unpack .../node-osenv_0.0.3-1_all.deb ...
Unpacking node-osenv (0.0.3-1) ...
Selecting previously unselected package node-tunnel-agent.
Preparing to unpack .../node-tunnel-agent_0.3.1-1_all.deb ...
Unpacking node-tunnel-agent (0.3.1-1) ...
Selecting previously unselected package node-json-stringify-safe.
Preparing to unpack .../node-json-stringify-safe_5.0.0-1_all.deb ...
Unpacking node-json-stringify-safe (5.0.0-1) ...
Selecting previously unselected package node-qs.
Preparing to unpack .../node-qs_0.6.5-1_all.deb ...
Unpacking node-qs (0.6.5-1) ...
Selecting previously unselected package node-request.
Preparing to unpack .../node-request_2.26.1-1_all.deb ...
Unpacking node-request (2.26.1-1) ...
Selecting previously unselected package node-semver.
Preparing to unpack .../node-semver_2.1.0-2_all.deb ...
Unpacking node-semver (2.1.0-2) ...
Selecting previously unselected package node-tar.
Preparing to unpack .../node-tar_0.1.18-1_all.deb ...
Unpacking node-tar (0.1.18-1) ...
Selecting previously unselected package node-which.
Preparing to unpack .../node-which_1.0.5-2_all.deb ...
Unpacking node-which (1.0.5-2) ...
Selecting previously unselected package node-gyp.
Preparing to unpack .../node-gyp_0.10.10-2_all.deb ...
Unpacking node-gyp (0.10.10-2) ...
Selecting previously unselected package node-ini.
Preparing to unpack .../node-ini_1.1.0-1_all.deb ...
Unpacking node-ini (1.1.0-1) ...
Selecting previously unselected package node-lockfile.
Preparing to unpack .../node-lockfile_0.4.1-1_all.deb ...
Unpacking node-lockfile (0.4.1-1) ...
Selecting previously unselected package node-mute-stream.
Preparing to unpack .../node-mute-stream_0.0.3-1_all.deb ...
Unpacking node-mute-stream (0.0.3-1) ...
Selecting previously unselected package node-normalize-package-data.
Preparing to unpack .../node-normalize-package-data_0.2.2-1_all.deb ...
Unpacking node-normalize-package-data (0.2.2-1) ...
Selecting previously unselected package node-once.
Preparing to unpack .../node-once_1.1.1-1_all.deb ...
Unpacking node-once (1.1.1-1) ...
Selecting previously unselected package node-read.
Preparing to unpack .../node-read_1.0.4-1_all.deb ...
Unpacking node-read (1.0.4-1) ...
Selecting previously unselected package node-read-package-json.
Preparing to unpack .../node-read-package-json_1.1.3-1_all.deb ...
Unpacking node-read-package-json (1.1.3-1) ...
Selecting previously unselected package node-retry.
Preparing to unpack .../node-retry_0.6.0-1_all.deb ...
Unpacking node-retry (0.6.0-1) ...
Selecting previously unselected package node-sha.
Preparing to unpack .../node-sha_1.2.3-1_all.deb ...
Unpacking node-sha (1.2.3-1) ...
Selecting previously unselected package node-slide.
Preparing to unpack .../node-slide_1.1.4-1_all.deb ...
Unpacking node-slide (1.1.4-1) ...
Selecting previously unselected package npm.
Preparing to unpack .../npm_1.3.10~dfsg-1_all.deb ...
Unpacking npm (1.3.10~dfsg-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 5 added doc-base files...
Setting up libc-ares2:i386 (1.10.0-2) ...
Setting up gyp (0.1~svn1729-3ubuntu1) ...
Setting up javascript-common (11) ...
Setting up libjs-node-uuid (1.4.0-1) ...
Setting up zlib1g-dev:i386 (1:1.2.8.dfsg-1ubuntu1) ...
Setting up libssl-dev:i386 (1.0.1f-1ubuntu2.15) ...
Setting up libssl-doc (1.0.1f-1ubuntu2.15) ...
Setting up libv8-3.14.5 (3.14.5.8-5ubuntu2) ...
Setting up libv8-3.14-dev (3.14.5.8-5ubuntu2) ...
Setting up nodejs (0.10.25~dfsg2-2ubuntu1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Setting up node-async (0.2.5-1) ...
Setting up node-node-uuid (1.4.0-1) ...
Setting up libc-ares-dev:i386 (1.10.0-2) ...
Setting up node-abbrev (1.0.4-2) ...
Setting up node-ansi (0.2.1-1) ...
Setting up node-archy (0.0.2-1) ...
Setting up node-inherits (2.0.0-1) ...
Setting up node-block-stream (0.0.7-1) ...
Setting up node-delayed-stream (0.0.5-1) ...
Setting up node-combined-stream (0.0.4-1) ...
Setting up node-cookie-jar (0.3.1-1) ...
Setting up node-forever-agent (0.5.1-1) ...
Setting up node-mime (1.2.11-1) ...
Setting up node-form-data (0.1.0-1) ...
Setting up node-rimraf (2.2.2-2) ...
Setting up node-mkdirp (0.3.5-1) ...
Setting up node-graceful-fs (2.0.0-2) ...
Setting up node-fstream (0.1.24-1) ...
Setting up node-lru-cache (2.3.1-1) ...
Setting up node-sigmund (1.0.0-1) ...
Setting up node-minimatch (0.2.12-1) ...
Setting up node-fstream-ignore (0.0.6-2) ...
Setting up node-github-url-from-git (1.1.1-1) ...
Setting up node-glob (3.2.6-1) ...
Setting up nodejs-dev (0.10.25~dfsg2-2ubuntu1) ...
Setting up node-nopt (2.1.2-1) ...
Setting up node-npmlog (0.0.4-1) ...
Setting up node-osenv (0.0.3-1) ...
Setting up node-tunnel-agent (0.3.1-1) ...
Setting up node-json-stringify-safe (5.0.0-1) ...
Setting up node-qs (0.6.5-1) ...
Setting up node-request (2.26.1-1) ...
Setting up node-semver (2.1.0-2) ...
Setting up node-tar (0.1.18-1) ...
Setting up node-which (1.0.5-2) ...
Setting up node-gyp (0.10.10-2) ...
Setting up node-ini (1.1.0-1) ...
Setting up node-lockfile (0.4.1-1) ...
Setting up node-mute-stream (0.0.3-1) ...
Setting up node-normalize-package-data (0.2.2-1) ...
Setting up node-once (1.1.1-1) ...
Setting up node-read (1.0.4-1) ...
Setting up node-read-package-json (1.1.3-1) ...
Setting up node-retry (0.6.0-1) ...
Setting up node-sha (1.2.3-1) ...
Setting up node-slide (1.1.4-1) ...
Setting up npm (1.3.10~dfsg-1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 01, 2015 - 12:32:31
Django version 1.8.3, using settings 'demonstration.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
===========
Django==1.8.3
django-nose==1.4.1
nose==1.3.7
requests==2.7.0
wsgiref==0.1.2
============
This tutorial assumes very little, so we’ll cover the following concepts throughout:
- Model, View, Controllers (MVC)
- JavaScript Object Notation (JSON)
- RESTful APIs
- Application flow within Django applications
Application Flow
The behavior of any Django Application (or web frameworks, in general) can be broken down as follows:- The user visits a URL, such as
/amazon/games
- This triggers a request to that URL, which is looked up in our URL dispatcher
- The URL dispatcher will map this URL to a function within our Views
- The corresponding View function will then access models, perform queries or fetch data as needed, which is bundled up and passed into a template
- The data passed into the template is then displayed to the user using HTML
Models, Views, Controllers
The core structure of any web framework can be broken into three parts: the Models, Views, and Controllers. This pattern allows developers to have a separation of concerns when building an application, and allows us to impose a logical structure to our projects. Let’s go over these parts in more detail.Models
Within a web framework, Models are your data layer. At any given time, your models will represent what your objects in your database will look like. For example, take a look at the following Django model shown below:from django.db import models
class Student(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
age = models.IntegerField()
first_name
, last_name
and age
will be fields in each Student
object. Django provides easy to use validation methods through CharField
, IntegerField
and much more, allowing model fields to only accept certain inputs.Under the hood, Django will use these models to create Structured Query Language, which in turn will store these models into a SQL database (MySQL, SQLite3, PostgreSQL). Using these methods, we won’t have to write our own database logic using SQL.
Views
A view is typically a visual representation of our underlying data layer (models). Views can update models as well as retrieve data from them through a query, which in turn would be passed to an HTML template.In Django, views generally consist of a combination of templates, the URL dispatcher, and a
views.py
file. When a user navigates to a URL, a callback function is run which maps that particular url (such as /games
) to a method named games
within views.py
which may in turn query models or some external API, and finally pass that data to a template using methods such as
render.Controllers
In Django, controllers are generally described as the underlying mechanisms of the framework itself which sends web requests to the appropriate view in combination with the URL dispatcher. In a sense, Django is more of a “Model, Template, View” framework as there are no explicit “Controllers”.RESTful APIs
Without getting too deep into the meaning of “RESTful API”, this term essentially means that there exists a web service which understands HTTP requests (GET, PUT/UPDATE, CREATE, DELETE). Any program that can send a web request (such as a Python program using the Requests library) can interact with these web service and receive data back in the form of either JSON or XML. This application will make use of the Requests library to send HTTP GET requests to Github’s RESTful API which in turn will return JSON, which we will parse and render through an HTML template.JSON
JavaScript Object Notation (JSON) is a way to store information in a lightweight, organized structure, containing a series of key/value pairs which can easily be parsed (extracted).JSON is used for websites such as Twitter, Facebook and Flickr to update asynchonously (without page reloads), and is the core in developing full-stack JavaScript applications. A sample snippet of JSON from Facebook can be seen below:
{
"data": [
{
"id": "X999_Y999",
"from": {
"name": "Tom Brady", "id": "X12"
},
"message": "Looking forward to 2010!",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X999/posts/Y999"
},
{
"name": "Like",
"link": "http://www.facebook.com/X999/posts/Y999"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
},
{
"id": "X998_Y998",
"from": {
"name": "Peyton Manning", "id": "X18"
},
"message": "Where's my contract?",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X998/posts/Y998"
},
{
"name": "Like",
"link": "http://www.facebook.com/X998/posts/Y998"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
}
]
}
Step 0: Installation
Before we can get started, we’ll need to get some dependencies out of the way. To begin, we’ll need to install the Python Package Manager,pip
. Mac, Linux and Windows users may refer here for instructions for installing pip
. Tip: I highly recommend creating a Virtual Environment. These environments allow you to effectively "sandbox" python packages, which is great for development.With
pip
in tow, we’ll install the following dependencies:- Django
- Requests
$ pip install django
$ pip install requests
Step 1: Starting our project
To kick things off, let’s create our Django project. Within your terminal:$ django-admin startproject demonstration
Warning: Avoid using names such as django or test, these names will collide with built-in Python packages.Let’s take a look at our brand new project:
demonstration/
├── demonstration
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
-
demonstration/manage.py: A command-line program allowing users to interact with their Django applications.
-
demonstration/demonstration/init.py: An empty file signifying that this directory is considered
a Python package.
-
demonstration/demonstration/settings.py:
A file consisting of key-value pairs for configuring your Django
application. You can configure your databases, setup paths to static
files, and much more.
-
demonstration/demonstration/urls.py:
Allows us to map view functions to URLs, which is essentially a table
of contents for our application. You can read much more about it here.
-
demonstration/demonstration/wsgi.py: Allows us to deploy WSGI-compatible web servers, which you can read about more here.
Running the server
Django comes pre-packaged with it’s own web server, which is pretty awesome. It allows us to run our application locally, and view any changes that we’ve made. To do so, let’s go ahead and run the following command:$ python manage.py runserver
Tip: I recommend having multiple terminal sessions open, one for having the Django server running, one for opening up text editors and one for comitting to a repository if you are using version control while building this application.When running this command, you’ll be greeted with the following error in your terminal:
Let’s go ahead and fix that. You can stop the server using
Control + C
(Command + C
on a Mac). Go ahead and run the following command:$ python manage.py migrate
This command will build all of the default database tables that Django needs for built-in services such as user authentication. For now, this isn’t too relevant to us.
Note: This will generate a db.sqlite3 database file, which would generally contain information regarding our models. For this project, we won't be dealing with the database.Once again, we’ll run the server:
$ python manage.py runserver
Great! You’ve run your first Django web application. However, as the message states, we haven’t configured any URLs yet. We’ll get to that shortly, but for now let’s actually create our application.
Step 2: Creating your application
You’re probably thinking, “Didn’t we already create our application?” Not quite, that was our project environment that we setup earlier. Within a Django Project, there can exist many “Applications”, one of which we’ll create right now:$ python manage.py startapp app
urls.py
and settings.py
file.app/
├── __init__.py
├── admin.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
-
app/admin.py: Allows us to register our models to view on the Django Admin Site.
-
app/migrations: Keeps track of our migrations which are essentially Django’s way of propagating changes that are made to our models.
-
app/models.py: Stores our representations of objects which will be stored in our database.
-
app/tests.py: Our unit tests will live here. Although Django calls these tests “unit tests”, they’re actually closer to integration tests.
-
app/views.py: All of our views will live here, which are mapped to URLs.
Settings.py
while which will be important going forward. Configuring Settings.py
Settings.py
contains various configuration options available, such as changing your database and so much more. For this project, we’ll need to add the following lines anywhere in this file:TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
Lastly, we’ll need to register your application (named app) under the Installed Apps section:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
)
Step 3: Your First View
As mentioned earlier, URLs map to functions in yourviews.py
which in turn will pass data to a template. Within app/views.py:# views.py
from django.shortcuts import render, HttpResponse
# Create your views here.
def index(request):
return HttpResponse('Hello World!')
Tip: Python has a great style guide, which I highly recommend taking a look at. At the very least, learn to adopt not mixing tabs with spaces, which will make your code consistent and avoid errors when running your Python code.In order to map urls to our view methods, we’ll need to configure them. Within our root URLs file within the demonstration folder, we’ll configure our urls to be proceeded by
app/
:# demonstration/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^app/', include('app.urls')),
url(r'^admin/', include(admin.site.urls)),
]
http://127.0.0.1:8000/app/<view url>
. We’ll now create a new urls.py
file within app/: $ cd ..
$ cd app
$ vim urls.py
# app/urls.py
from django.conf.urls import url
from app import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
Tip: You can read more about URL configuration here.After configuring your app/urls.py as shown, you should be prompted with the following response when you navigate to http://127.0.0.1:8000/app/:
We’ve successfully mapped the
/app/
url to the index
function within app/views.py.
Pretty simple, right? At this point,
can you see the application flow that we described earlier? To further
emphasize this, try and see if you can create a new url, map it to your
view, and display the string My second view!
on your own. We’ll include the code to do so below:# app/urls.py
from django.conf.urls import url
from app import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^test/$', views.test, name='test'),
]
# views.py
from django.shortcuts import render, HttpResponse
import requests
# Create your views here.
def index(request):
return HttpResponse('Hello World!')
def test(request):
return HttpResponse('My second view!')
Alright, you should be getting the hang of it now. We’ve been making some toy views, but how about we move onto displaying some meaningful data to the user? In particular, we’ll display the Github profile information for a given user.
Step 4: Integrating the Github API
The Github API contains a collection of URLs which a developer can query using HTTP methods to retrieve data, in the form of JSON. In order to leverage this API, we’ll use the Python Requests library which will make this process simple. From the API for users, we can get profile information by using the following URL:https://api.github.com/users/:user
$ python
>>> import requests
>>> req = requests.get('https://api.github.com/users/DrkSephy')
>>> print req.content
{
"login": "DrkSephy",
"id": 1226900,
"avatar_url": "https://avatars.githubusercontent.com/u/1226900?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/DrkSephy",
"html_url": "https://github.com/DrkSephy",
"followers_url": "https://api.github.com/users/DrkSephy/followers",
"following_url": "https://api.github.com/users/DrkSephy/following{/other_user}",
"gists_url": "https://api.github.com/users/DrkSephy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/DrkSephy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/DrkSephy/subscriptions",
"organizations_url": "https://api.github.com/users/DrkSephy/orgs",
"repos_url": "https://api.github.com/users/DrkSephy/repos",
"events_url": "https://api.github.com/users/DrkSephy/events{/privacy}",
"received_events_url": "https://api.github.com/users/DrkSephy/received_events",
"type": "User",
"site_admin": false,
"name": "David Leonard",
"company": "Yahoo!",
"blog": "http://drksephy.github.io",
"location": "Sunnyvale, California",
"email": "DrkSephy1025@gmail.com",
"hireable": false,
"bio": null,
"public_repos": 68,
"public_gists": 5,
"followers": 127,
"following": 6,
"created_at": "2011-11-29T01:15:27Z",
"updated_at": "2015-07-17T13:17:54Z"
}
# app/urls.py
from django.conf.urls import url
from app import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^test/$', views.test, name='test'),
url(r'^profile/$', views.profile, name='profile'),
]
import json
as shown in the code snippet below:# views.py
from django.shortcuts import render, HttpResponse
import requests
import json
# Create your views here.
def index(request):
return HttpResponse('Hello World!')
def test(request):
return HttpResponse('My second view!')
def profile(request):
req = requests.get('https://api.github.com/users/DrkSephy')
content = req.text
return HttpResponse(content)
At the moment, the output is kind of messy. Let’s update our view
profile
view to bundle up the values in the JSON that we are interested in displaying to the user:def profile(request):
jsonList = []
req = requests.get('https://api.github.com/users/DrkSephy')
jsonList.append(json.loads(req.content))
parsedData = []
userData = {}
for data in jsonList:
userData['name'] = data['name']
userData['blog'] = data['blog']
userData['email'] = data['email']
userData['public_gists'] = data['public_gists']
userData['public_repos'] = data['public_repos']
userData['avatar_url'] = data['avatar_url']
userData['followers'] = data['followers']
userData['following'] = data['following']
parsedData.append(userData)
return HttpResponse(parsedData)
As of now, we’ve covered a bunch of topics in only < 30 lines of Python. Let’s take a moment to recap what we’ve learned:
- Creating our project structure
- Learned the basics of MVC
- Mapping our URLs
- Writing several view methods
- APIs, and how to query data using Requests
- Displaying data to the user
Bower
Bower is a front-end dependency manager for your project. In laymans terms, it is a command-line program which you can utilize to download libraries such as Twitter Bootstrap. The beauty of this approach is that we can generate abower.json
file, which any user can copy and use to download a bunch of packages
easily - as opposed to going to each site, and manually
copy/pasting/saving out files. In this step, I’ll walk you through downloading Twitter bootstrap as well as generating your own
bower.json
. Before we do this, we’ll create a .bowerrc
file.In the same directory as
manage.py
, create a .bowerrc
file with the following content:{
"directory": "app/static/"
}
bower
, it will output the downloaded files within the directory listed here. Tip: There is a huge array of configuration options which can be used, for those curious.And now in our command line, we can simply run:
$ bower install bootstrap
.bowerrc
file. Step 5: Templating
Templates in Django are essentially HTML files which we pass in a context which then renders our data to the user. Before we can create our first template, we’ll need to create some folders. In the same directory as your app/views.py:$ mkdir templates
$ mkdir templates/app
$ cd templates/app
profile.html
:<!DOCTYPE html>
<html>
<head>
<script src="/static/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/bootstrap/dist/css/bootstrap-theme.min.css">
</head>
<body>
<h1 class="text-center"> Github User Data </h1>
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header"> Username <i class="icon-sort"></i></th>
<th class="header"> Blog <i class="icon-sort"></i></th>
<th class="header"> Public Repos <i class="icon-sort"></i></th>
<th class="header"> Public Gists <i class="icon-sort"></i></th>
<th class="header"> Email <i class="icon-sort"></i></th>
<th class="header"> Followers <i class="icon-sort"></i></th>
<th class="header"> Following <i class="icon-sort"></i></th>
</tr>
</thead>
<tbody>
{% for key in data %}
<tr>
<td>{{ key.name }}</td>
<td>{{ key.blog }}</td>
<td>{{ key.public_repos }}</td>
<td>{{ key.public_gists }}</td>
<td>{{ key.email }}</td>
<td>{{ key.followers }}</td>
<td>{{ key.following }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
</html>
{% for key in data %}
{% endfor %}
for
loop, which should look familiar. Within this for
loop, we do the following:{{ key.name }}
{{ key.blog }}
{{ key.public_repos }}
...
data
is an array of dictionaries, in which each dictionary has the name
, blog
, and public_repos
keys (and a few others, listed in the above snippet for brevity). Here
we access these properties and display them using the double curly
braces syntax, which are template varaible placeholders which will take
on the value of the expression within. Tip: For deeper insight to templating and variables, check out the documentation here.With this new template in hand, let’s reload our
profile
page:Awesome, we’ve got a nice layout. As of now, our view method is essentially hardcoded - we can’t query any particular user’s Github information. We’ll need to come up with a way to ask the user for an input, and to do this we’ll move onto forms.
Step 6: Forms
Forms are the bread and butter of web applications - every web programmer will come across them at one point or another. Forms essentially allow users to interact with your web application through various fields for input, usually for registration pages or in our case, performing a query.To begin, we’ll go ahead and build our form within our
profile.html
:<style>
.form-signin {
max-width: 550px;
padding: 15px;
margin: 0 auto;
}
</style>
<div class="container text-center">
<form class="form-signin" id="login_form" method="post" action="/app/profile/">
{% csrf_token %}
<br>
<input type="text" name="user" class="form-control" placeholder="Github User Name, e.g: DrkSephy" value="" required autofocus>
<br>
<button class="btn btn-lg btn-primary btn-block" type="submit">Get Data</button>
</form>
</div>
<style>
.form-signin {
max-width: 550px;
padding: 15px;
margin: 0 auto;
}
</style>
<div class="container text-center">
<form class="form-signin" method="post" action="/app/profile/">
...
</form>
</div>
form
element which is styled by our CSS class using:<form class="form-signin" ... >
<form ... method="post" ... >
<form ... ... action="/app/profile/">
/app/profile/
is our view function which will handle the POST request.{% csrf_token %}
csrf_token
will protect against any cross site forgery attacks.Next, we look at our input field:
<input type="text" name="user" class="form-control" placeholder="Github User Name, e.g: DrkSephy" required autofocus>
<!-- The type of input the field is expecting -->
<input type="text" ... >
<!-- This key/value pair will be sent as a POST parameter upon submission -->
<input ... name="user" ... >
<!-- placeholder text for the form field -->
<input ... placeholder="Github User Name, e.g: DrkSephy" ... >
<!-- make a blue border around the form field when user has clicked to type -->
<input ... required autofocus>
name=user
. This name
parameter will have it’s value user
sent as a POST parameter once the user submits the form, which we’ll
get into shortly. The last bit for our form is the actual submission,
which will be a button:<button class="btn btn-lg btn-primary btn-block" type="submit">Get Data</button>
btn btn-lg btn-primary btn-block
, as well as the type of action to perform when this button is clicked (in this case, a submit
action.) Once this button is clicked, the form will be submitted and
the values from it’s form fields (here we only have one form field) will
be sent as a POST request to the corresponding URL set earlier.Putting it all together:
<!DOCTYPE html>
<html>
<head>
<script src="/static/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/bootstrap/dist/css/bootstrap-theme.min.css">
</head>
<body>
<h1 class="text-center"> Github User Data </h1>
<div class="col-lg-12">
<style>
.form-signin {
max-width: 550px;
padding: 15px;
margin: 0 auto;
}
</style>
<div class="container text-center">
<form class="form-signin" id="login_form" method="post" action="/app/profile/">
{% csrf_token %}
<br>
<input type="text" name="user" class="form-control" placeholder="Github User Name, e.g: DrkSephy" value="" required autofocus>
<br>
<button class="btn btn-lg btn-primary btn-block" type="submit">Get Data</button>
</form>
</div>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header"> Username <i class="icon-sort"></i></th>
<th class="header"> Blog <i class="icon-sort"></i></th>
<th class="header"> Public Repos <i class="icon-sort"></i></th>
<th class="header"> Public Gists <i class="icon-sort"></i></th>
<th class="header"> Email <i class="icon-sort"></i></th>
<th class="header"> Followers <i class="icon-sort"></i></th>
<th class="header"> Following <i class="icon-sort"></i></th>
</tr>
</thead>
<tbody>
{% for key in data %}
<tr>
<td>{{ key.name }}</td>
<td>{{ key.blog }}</td>
<td>{{ key.public_repos }}</td>
<td>{{ key.public_gists }}</td>
<td>{{ key.email }}</td>
<td>{{ key.followers }}</td>
<td>{{ key.following }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
</html>
Step 7: Capturing POST parameters
As mentioned, performing a POST request will send parameters that can be accessed programmatically. Let’s modify ourprofile
method within app/views.py to access the user
value that was passed through our form submission:def profile(request):
parsedData = []
if request.method == 'POST':
username = request.POST.get('user')
req = requests.get('https://api.github.com/users/' + username)
jsonList = []
jsonList.append(json.loads(req.content))
userData = {}
for data in jsonList:
userData['name'] = data['name']
userData['blog'] = data['blog']
userData['email'] = data['email']
userData['public_gists'] = data['public_gists']
userData['public_repos'] = data['public_repos']
userData['avatar_url'] = data['avatar_url']
userData['followers'] = data['followers']
userData['following'] = data['following']
parsedData.append(userData)
return render(request, 'app/profile.html', {'data': parsedData})
if request.method == 'POST':
profile
method was accessed through a POST
request, this condition will be true. Likewise, we could write additional logic to handle cases for GET
, UPDATE
, and DELETE
requests here based on the type of request we specified in our form. username = request.POST.get('user')
name
with a corresponding value user
, which was passed upon form submission. We’ll use this value to build a request url:req = requests.get('https://api.github.com/users/' + username)
I hope this guide has been helpful for beginners (and possibly non-beginners). I’ll be exploring more complicated tech stacks using Django + ReactJS in the near future, so stay tuned for more tutorials.
Thanks for reading.
===================
Installation
To install the required libraries for this file, simply run the following:pip install -r requirements.txt
This project also requires using Bower, which requires NPM. In order to get NPM, simple install Node.js. Once you have node, you can install Bower:npm install -g bower
Note: On a Mac, you'll need to use:sudo npm install -g bower
With Bower, you can install the front-end dependencies by running:bower install
This will generate the static folder along with bootstrap and jquery inside it.Running the project
To run this project:# Navigate into directory containing manage.py
cd demonstration
# Setup the database
python manage.py migrate
python manage.py makemigrations
# Run the server
python manage.py runserver
You can now visit the following URLS:* http://127.0.0.1:8000/app/
* http://127.0.0.1:8000/app/test/
* http://127.0.0.1:8000/app/profile/
Tests
Run the test suite:python manage.py test
================================
terminal
===============================
erp@erp-OptiPlex-330:~$ mkdir boot
erp@erp-OptiPlex-330:~$ cd boot
erp@erp-OptiPlex-330:~/boot$ virtualenv boot
New python executable in boot/bin/python
Installing setuptools, pip, wheel...done.
erp@erp-OptiPlex-330:~/boot$ ls
boot
erp@erp-OptiPlex-330:~/boot$ source /boot/bin/activate
bash: /boot/bin/activate: No such file or directory
erp@erp-OptiPlex-330:~/boot$ ls
boot
erp@erp-OptiPlex-330:~/boot$ cd boot
erp@erp-OptiPlex-330:~/boot/boot$ ls
bin django include lib local
erp@erp-OptiPlex-330:~/boot/boot$ source ./bin/activate
(boot)erp@erp-OptiPlex-330:~/boot/boot$ ls
bin django include lib local
(boot)erp@erp-OptiPlex-330:~/boot/boot$ cd django
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ ls
app bower.json demonstration manage.py README.md requirements.txt
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ pip install -r requirements.txt
/home/erp/boot/boot/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting Django==1.8.3 (from -r requirements.txt (line 1))
/home/erp/boot/boot/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Using cached Django-1.8.3-py2.py3-none-any.whl
Collecting django-nose==1.4.1 (from -r requirements.txt (line 2))
Downloading django_nose-1.4.1-py2-none-any.whl
Collecting nose==1.3.7 (from -r requirements.txt (line 3))
Downloading nose-1.3.7-py2-none-any.whl (154kB)
100% |████████████████████████████████| 155kB 1.6MB/s
Collecting requests==2.7.0 (from -r requirements.txt (line 4))
Downloading requests-2.7.0-py2.py3-none-any.whl (470kB)
100% |████████████████████████████████| 471kB 564kB/s
Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt (line 5))
Installing collected packages: Django, nose, django-nose, requests
Successfully installed Django-1.8.3 django-nose-1.4.1 nose-1.3.7 requests-2.7.0
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py syncdb
/home/erp/boot/boot/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages, django_nose
Apply all migrations: admin, contenttypes, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'erp'): erp
Email address: erp@gmail.com
Password:
Password (again):
Superuser created successfully.
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 01, 2015 - 12:29:57
Django version 1.8.3, using settings 'demonstration.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
pip install -r requirements.txt[01/Sep/2015 12:30:02]"GET / HTTP/1.1" 404 2015
[01/Sep/2015 12:30:06]"GET /app HTTP/1.1" 301 0
[01/Sep/2015 12:30:06]"GET /app/ HTTP/1.1" 200 12
[01/Sep/2015 12:30:12]"GET /admin HTTP/1.1" 301 0
[01/Sep/2015 12:30:12]"GET /admin/ HTTP/1.1" 302 0
[01/Sep/2015 12:30:12]"GET /admin/login/?next=/admin/ HTTP/1.1" 200 1915
[01/Sep/2015 12:30:12]"GET /static/admin/css/login.css HTTP/1.1" 200 940
[01/Sep/2015 12:30:12]"GET /static/admin/css/base.css HTTP/1.1" 200 14049
[01/Sep/2015 12:30:12]"GET /static/admin/img/nav-bg.gif HTTP/1.1" 200 265
[01/Sep/2015 12:30:16]"POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[01/Sep/2015 12:30:16]"GET /admin/ HTTP/1.1" 200 3018
[01/Sep/2015 12:30:16]"GET /static/admin/css/dashboard.css HTTP/1.1" 200 434
[01/Sep/2015 12:30:16]"GET /static/admin/img/default-bg.gif HTTP/1.1" 200 836
[01/Sep/2015 12:30:16]"GET /static/admin/img/icon_changelink.gif HTTP/1.1" 200 119
[01/Sep/2015 12:30:16]"GET /static/admin/img/icon_addlink.gif HTTP/1.1" 200 119
[01/Sep/2015 12:30:19]"GET /admin/auth/user/ HTTP/1.1" 200 6598
[01/Sep/2015 12:30:19]"GET /static/admin/css/changelists.css HTTP/1.1" 200 5254
[01/Sep/2015 12:30:19]"GET /static/admin/js/jquery.init.js HTTP/1.1" 200 326
[01/Sep/2015 12:30:19]"GET /static/admin/js/actions.js HTTP/1.1" 200 4910
[01/Sep/2015 12:30:19]"GET /static/admin/js/jquery.js HTTP/1.1" 200 284184
[01/Sep/2015 12:30:19]"GET /static/admin/js/core.js HTTP/1.1" 200 7522
[01/Sep/2015 12:30:19]"GET /static/admin/js/admin/RelatedObjectLookups.js HTTP/1.1" 200 4464
[01/Sep/2015 12:30:19]"GET /admin/jsi18n/ HTTP/1.1" 200 2372
[01/Sep/2015 12:30:19]"GET /static/admin/img/icon-yes.gif HTTP/1.1" 200 299
[01/Sep/2015 12:30:19]"GET /static/admin/img/changelist-bg.gif HTTP/1.1" 200 50
[01/Sep/2015 12:30:19]"GET /static/admin/img/icon_searchbox.png HTTP/1.1" 200 368
[01/Sep/2015 12:30:19]"GET /static/admin/img/tooltag-add.png HTTP/1.1" 200 119
[01/Sep/2015 12:30:19]"GET /static/admin/img/nav-bg-reverse.gif HTTP/1.1" 200 178
[01/Sep/2015 12:30:19]"GET /static/admin/img/nav-bg-selected.gif HTTP/1.1" 200 265
[01/Sep/2015 12:30:19]"GET /static/admin/img/sorting-icons.gif HTTP/1.1" 200 369
[01/Sep/2015 12:30:22]"GET /admin/auth/group/ HTTP/1.1" 200 3590
[01/Sep/2015 12:30:22]"GET /admin/jsi18n/ HTTP/1.1" 200 2372
[01/Sep/2015 12:30:22]"GET /static/admin/css/base.css HTTP/1.1" 304 0
[01/Sep/2015 12:30:23]"GET /static/admin/img/nav-bg.gif HTTP/1.1" 304 0
^C(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ npm install -g bower
The program 'npm' is currently not installed. You can install it by typing:
sudo apt-get install npm
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ sudo apt-get install npm
[sudo] password for erp:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
account-plugin-windows-live libupstart1 linux-headers-3.16.0-30
linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic
linux-image-extra-3.16.0-30-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libssl-dev
libssl-doc libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-archy
node-async node-block-stream node-combined-stream node-cookie-jar
node-delayed-stream node-forever-agent node-form-data node-fstream
node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream
node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once
node-osenv node-qs node-read node-read-package-json node-request node-retry
node-rimraf node-semver node-sha node-sigmund node-slide node-tar
node-tunnel-agent node-which nodejs nodejs-dev zlib1g-dev
Suggested packages:
apache2 lighttpd httpd node-hawk node-aws-sign node-oauth-sign
node-http-signature
The following NEW packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libssl-dev
libssl-doc libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-archy
node-async node-block-stream node-combined-stream node-cookie-jar
node-delayed-stream node-forever-agent node-form-data node-fstream
node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream
node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once
node-osenv node-qs node-read node-read-package-json node-request node-retry
node-rimraf node-semver node-sha node-sigmund node-slide node-tar
node-tunnel-agent node-which nodejs nodejs-dev npm zlib1g-dev
0 upgraded, 57 newly installed, 0 to remove and 13 not upgraded.
Need to get 5,378 kB of archives.
After this operation, 20.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/main libc-ares2 i386 1.10.0-2 [38.3 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu/ trusty/universe gyp all 0.1~svn1729-3ubuntu1 [201 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ trusty/main javascript-common all 11 [6,066 B]
Get:4 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libjs-node-uuid all 1.4.0-1 [11.1 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu/ trusty/main zlib1g-dev i386 1:1.2.8.dfsg-1ubuntu1 [181 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main libssl-dev i386 1.0.1f-1ubuntu2.15 [989 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main libssl-doc all 1.0.1f-1ubuntu2.15 [966 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libv8-3.14.5 i386 3.14.5.8-5ubuntu2 [1,192 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu/ trusty/universe libv8-3.14-dev i386 3.14.5.8-5ubuntu2 [57.6 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu/ trusty/universe nodejs i386 0.10.25~dfsg2-2ubuntu1 [689 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-async all 0.2.5-1 [17.7 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-node-uuid all 1.4.0-1 [2,530 B]
Get:13 http://in.archive.ubuntu.com/ubuntu/ trusty/main libc-ares-dev i386 1.10.0-2 [104 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-abbrev all 1.0.4-2 [3,814 B]
Get:15 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-ansi all 0.2.1-1 [8,692 B]
Get:16 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-archy all 0.0.2-1 [3,660 B]
Get:17 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-inherits all 2.0.0-1 [3,090 B]
Get:18 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-block-stream all 0.0.7-1 [4,832 B]
Get:19 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-delayed-stream all 0.0.5-1 [4,750 B]
Get:20 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-combined-stream all 0.0.4-1 [4,686 B]
Get:21 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-cookie-jar all 0.3.1-1 [3,746 B]
Get:22 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-forever-agent all 0.5.1-1 [3,194 B]
Get:23 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mime all 1.2.11-1 [20.2 kB]
Get:24 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-form-data all 0.1.0-1 [6,412 B]
Get:25 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-rimraf all 2.2.2-2 [5,392 B]
Get:26 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mkdirp all 0.3.5-1 [4,146 B]
Get:27 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-graceful-fs all 2.0.0-2 [6,718 B]
Get:28 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-fstream all 0.1.24-1 [19.5 kB]
Get:29 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-lru-cache all 2.3.1-1 [5,674 B]
Get:30 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-sigmund all 1.0.0-1 [3,818 B]
Get:31 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-minimatch all 0.2.12-1 [14.9 kB]
Get:32 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-fstream-ignore all 0.0.6-2 [5,586 B]
Get:33 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-github-url-from-git all 1.1.1-1 [3,138 B]
Get:34 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-glob all 3.2.6-1 [13.7 kB]
Get:35 http://in.archive.ubuntu.com/ubuntu/ trusty/universe nodejs-dev i386 0.10.25~dfsg2-2ubuntu1 [168 kB]
Get:36 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-nopt all 2.1.2-1 [11.8 kB]
Get:37 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-npmlog all 0.0.4-1 [5,844 B]
Get:38 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-osenv all 0.0.3-1 [3,810 B]
Get:39 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-tunnel-agent all 0.3.1-1 [4,018 B]
Get:40 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-json-stringify-safe all 5.0.0-1 [3,544 B]
Get:41 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-qs all 0.6.5-1 [5,876 B]
Get:42 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-request all 2.26.1-1 [14.5 kB]
Get:43 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-semver all 2.1.0-2 [16.2 kB]
Get:44 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-tar all 0.1.18-1 [18.3 kB]
Get:45 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-which all 1.0.5-2 [3,678 B]
Get:46 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-gyp all 0.10.10-2 [22.6 kB]
Get:47 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-ini all 1.1.0-1 [4,770 B]
Get:48 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-lockfile all 0.4.1-1 [5,450 B]
Get:49 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-mute-stream all 0.0.3-1 [3,738 B]
Get:50 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-normalize-package-data all 0.2.2-1 [9,286 B]
Get:51 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-once all 1.1.1-1 [2,608 B]
Get:52 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-read all 1.0.4-1 [4,282 B]
Get:53 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-read-package-json all 1.1.3-1 [7,762 B]
Get:54 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-retry all 0.6.0-1 [6,172 B]
Get:55 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-sha all 1.2.3-1 [4,272 B]
Get:56 http://in.archive.ubuntu.com/ubuntu/ trusty/universe node-slide all 1.1.4-1 [6,118 B]
Get:57 http://in.archive.ubuntu.com/ubuntu/ trusty/universe npm all 1.3.10~dfsg-1 [442 kB]
Fetched 5,378 kB in 16s (320 kB/s)
Extracting templates from packages: 100%
Selecting previously unselected package libc-ares2:i386.
(Reading database ... 243598 files and directories currently installed.)
Preparing to unpack .../libc-ares2_1.10.0-2_i386.deb ...
Unpacking libc-ares2:i386 (1.10.0-2) ...
Selecting previously unselected package gyp.
Preparing to unpack .../gyp_0.1~svn1729-3ubuntu1_all.deb ...
Unpacking gyp (0.1~svn1729-3ubuntu1) ...
Selecting previously unselected package javascript-common.
Preparing to unpack .../javascript-common_11_all.deb ...
Unpacking javascript-common (11) ...
Selecting previously unselected package libjs-node-uuid.
Preparing to unpack .../libjs-node-uuid_1.4.0-1_all.deb ...
Unpacking libjs-node-uuid (1.4.0-1) ...
Selecting previously unselected package zlib1g-dev:i386.
Preparing to unpack .../zlib1g-dev_1%3a1.2.8.dfsg-1ubuntu1_i386.deb ...
Unpacking zlib1g-dev:i386 (1:1.2.8.dfsg-1ubuntu1) ...
Selecting previously unselected package libssl-dev:i386.
Preparing to unpack .../libssl-dev_1.0.1f-1ubuntu2.15_i386.deb ...
Unpacking libssl-dev:i386 (1.0.1f-1ubuntu2.15) ...
Selecting previously unselected package libssl-doc.
Preparing to unpack .../libssl-doc_1.0.1f-1ubuntu2.15_all.deb ...
Unpacking libssl-doc (1.0.1f-1ubuntu2.15) ...
Selecting previously unselected package libv8-3.14.5.
Preparing to unpack .../libv8-3.14.5_3.14.5.8-5ubuntu2_i386.deb ...
Unpacking libv8-3.14.5 (3.14.5.8-5ubuntu2) ...
Selecting previously unselected package libv8-3.14-dev.
Preparing to unpack .../libv8-3.14-dev_3.14.5.8-5ubuntu2_i386.deb ...
Unpacking libv8-3.14-dev (3.14.5.8-5ubuntu2) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_0.10.25~dfsg2-2ubuntu1_i386.deb ...
Unpacking nodejs (0.10.25~dfsg2-2ubuntu1) ...
Selecting previously unselected package node-async.
Preparing to unpack .../node-async_0.2.5-1_all.deb ...
Unpacking node-async (0.2.5-1) ...
Selecting previously unselected package node-node-uuid.
Preparing to unpack .../node-node-uuid_1.4.0-1_all.deb ...
Unpacking node-node-uuid (1.4.0-1) ...
Selecting previously unselected package libc-ares-dev:i386.
Preparing to unpack .../libc-ares-dev_1.10.0-2_i386.deb ...
Unpacking libc-ares-dev:i386 (1.10.0-2) ...
Selecting previously unselected package node-abbrev.
Preparing to unpack .../node-abbrev_1.0.4-2_all.deb ...
Unpacking node-abbrev (1.0.4-2) ...
Selecting previously unselected package node-ansi.
Preparing to unpack .../node-ansi_0.2.1-1_all.deb ...
Unpacking node-ansi (0.2.1-1) ...
Selecting previously unselected package node-archy.
Preparing to unpack .../node-archy_0.0.2-1_all.deb ...
Unpacking node-archy (0.0.2-1) ...
Selecting previously unselected package node-inherits.
Preparing to unpack .../node-inherits_2.0.0-1_all.deb ...
Unpacking node-inherits (2.0.0-1) ...
Selecting previously unselected package node-block-stream.
Preparing to unpack .../node-block-stream_0.0.7-1_all.deb ...
Unpacking node-block-stream (0.0.7-1) ...
Selecting previously unselected package node-delayed-stream.
Preparing to unpack .../node-delayed-stream_0.0.5-1_all.deb ...
Unpacking node-delayed-stream (0.0.5-1) ...
Selecting previously unselected package node-combined-stream.
Preparing to unpack .../node-combined-stream_0.0.4-1_all.deb ...
Unpacking node-combined-stream (0.0.4-1) ...
Selecting previously unselected package node-cookie-jar.
Preparing to unpack .../node-cookie-jar_0.3.1-1_all.deb ...
Unpacking node-cookie-jar (0.3.1-1) ...
Selecting previously unselected package node-forever-agent.
Preparing to unpack .../node-forever-agent_0.5.1-1_all.deb ...
Unpacking node-forever-agent (0.5.1-1) ...
Selecting previously unselected package node-mime.
Preparing to unpack .../node-mime_1.2.11-1_all.deb ...
Unpacking node-mime (1.2.11-1) ...
Selecting previously unselected package node-form-data.
Preparing to unpack .../node-form-data_0.1.0-1_all.deb ...
Unpacking node-form-data (0.1.0-1) ...
Selecting previously unselected package node-rimraf.
Preparing to unpack .../node-rimraf_2.2.2-2_all.deb ...
Unpacking node-rimraf (2.2.2-2) ...
Selecting previously unselected package node-mkdirp.
Preparing to unpack .../node-mkdirp_0.3.5-1_all.deb ...
Unpacking node-mkdirp (0.3.5-1) ...
Selecting previously unselected package node-graceful-fs.
Preparing to unpack .../node-graceful-fs_2.0.0-2_all.deb ...
Unpacking node-graceful-fs (2.0.0-2) ...
Selecting previously unselected package node-fstream.
Preparing to unpack .../node-fstream_0.1.24-1_all.deb ...
Unpacking node-fstream (0.1.24-1) ...
Selecting previously unselected package node-lru-cache.
Preparing to unpack .../node-lru-cache_2.3.1-1_all.deb ...
Unpacking node-lru-cache (2.3.1-1) ...
Selecting previously unselected package node-sigmund.
Preparing to unpack .../node-sigmund_1.0.0-1_all.deb ...
Unpacking node-sigmund (1.0.0-1) ...
Selecting previously unselected package node-minimatch.
Preparing to unpack .../node-minimatch_0.2.12-1_all.deb ...
Unpacking node-minimatch (0.2.12-1) ...
Selecting previously unselected package node-fstream-ignore.
Preparing to unpack .../node-fstream-ignore_0.0.6-2_all.deb ...
Unpacking node-fstream-ignore (0.0.6-2) ...
Selecting previously unselected package node-github-url-from-git.
Preparing to unpack .../node-github-url-from-git_1.1.1-1_all.deb ...
Unpacking node-github-url-from-git (1.1.1-1) ...
Selecting previously unselected package node-glob.
Preparing to unpack .../node-glob_3.2.6-1_all.deb ...
Unpacking node-glob (3.2.6-1) ...
Selecting previously unselected package nodejs-dev.
Preparing to unpack .../nodejs-dev_0.10.25~dfsg2-2ubuntu1_i386.deb ...
Unpacking nodejs-dev (0.10.25~dfsg2-2ubuntu1) ...
Selecting previously unselected package node-nopt.
Preparing to unpack .../node-nopt_2.1.2-1_all.deb ...
Unpacking node-nopt (2.1.2-1) ...
Selecting previously unselected package node-npmlog.
Preparing to unpack .../node-npmlog_0.0.4-1_all.deb ...
Unpacking node-npmlog (0.0.4-1) ...
Selecting previously unselected package node-osenv.
Preparing to unpack .../node-osenv_0.0.3-1_all.deb ...
Unpacking node-osenv (0.0.3-1) ...
Selecting previously unselected package node-tunnel-agent.
Preparing to unpack .../node-tunnel-agent_0.3.1-1_all.deb ...
Unpacking node-tunnel-agent (0.3.1-1) ...
Selecting previously unselected package node-json-stringify-safe.
Preparing to unpack .../node-json-stringify-safe_5.0.0-1_all.deb ...
Unpacking node-json-stringify-safe (5.0.0-1) ...
Selecting previously unselected package node-qs.
Preparing to unpack .../node-qs_0.6.5-1_all.deb ...
Unpacking node-qs (0.6.5-1) ...
Selecting previously unselected package node-request.
Preparing to unpack .../node-request_2.26.1-1_all.deb ...
Unpacking node-request (2.26.1-1) ...
Selecting previously unselected package node-semver.
Preparing to unpack .../node-semver_2.1.0-2_all.deb ...
Unpacking node-semver (2.1.0-2) ...
Selecting previously unselected package node-tar.
Preparing to unpack .../node-tar_0.1.18-1_all.deb ...
Unpacking node-tar (0.1.18-1) ...
Selecting previously unselected package node-which.
Preparing to unpack .../node-which_1.0.5-2_all.deb ...
Unpacking node-which (1.0.5-2) ...
Selecting previously unselected package node-gyp.
Preparing to unpack .../node-gyp_0.10.10-2_all.deb ...
Unpacking node-gyp (0.10.10-2) ...
Selecting previously unselected package node-ini.
Preparing to unpack .../node-ini_1.1.0-1_all.deb ...
Unpacking node-ini (1.1.0-1) ...
Selecting previously unselected package node-lockfile.
Preparing to unpack .../node-lockfile_0.4.1-1_all.deb ...
Unpacking node-lockfile (0.4.1-1) ...
Selecting previously unselected package node-mute-stream.
Preparing to unpack .../node-mute-stream_0.0.3-1_all.deb ...
Unpacking node-mute-stream (0.0.3-1) ...
Selecting previously unselected package node-normalize-package-data.
Preparing to unpack .../node-normalize-package-data_0.2.2-1_all.deb ...
Unpacking node-normalize-package-data (0.2.2-1) ...
Selecting previously unselected package node-once.
Preparing to unpack .../node-once_1.1.1-1_all.deb ...
Unpacking node-once (1.1.1-1) ...
Selecting previously unselected package node-read.
Preparing to unpack .../node-read_1.0.4-1_all.deb ...
Unpacking node-read (1.0.4-1) ...
Selecting previously unselected package node-read-package-json.
Preparing to unpack .../node-read-package-json_1.1.3-1_all.deb ...
Unpacking node-read-package-json (1.1.3-1) ...
Selecting previously unselected package node-retry.
Preparing to unpack .../node-retry_0.6.0-1_all.deb ...
Unpacking node-retry (0.6.0-1) ...
Selecting previously unselected package node-sha.
Preparing to unpack .../node-sha_1.2.3-1_all.deb ...
Unpacking node-sha (1.2.3-1) ...
Selecting previously unselected package node-slide.
Preparing to unpack .../node-slide_1.1.4-1_all.deb ...
Unpacking node-slide (1.1.4-1) ...
Selecting previously unselected package npm.
Preparing to unpack .../npm_1.3.10~dfsg-1_all.deb ...
Unpacking npm (1.3.10~dfsg-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 5 added doc-base files...
Setting up libc-ares2:i386 (1.10.0-2) ...
Setting up gyp (0.1~svn1729-3ubuntu1) ...
Setting up javascript-common (11) ...
Setting up libjs-node-uuid (1.4.0-1) ...
Setting up zlib1g-dev:i386 (1:1.2.8.dfsg-1ubuntu1) ...
Setting up libssl-dev:i386 (1.0.1f-1ubuntu2.15) ...
Setting up libssl-doc (1.0.1f-1ubuntu2.15) ...
Setting up libv8-3.14.5 (3.14.5.8-5ubuntu2) ...
Setting up libv8-3.14-dev (3.14.5.8-5ubuntu2) ...
Setting up nodejs (0.10.25~dfsg2-2ubuntu1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Setting up node-async (0.2.5-1) ...
Setting up node-node-uuid (1.4.0-1) ...
Setting up libc-ares-dev:i386 (1.10.0-2) ...
Setting up node-abbrev (1.0.4-2) ...
Setting up node-ansi (0.2.1-1) ...
Setting up node-archy (0.0.2-1) ...
Setting up node-inherits (2.0.0-1) ...
Setting up node-block-stream (0.0.7-1) ...
Setting up node-delayed-stream (0.0.5-1) ...
Setting up node-combined-stream (0.0.4-1) ...
Setting up node-cookie-jar (0.3.1-1) ...
Setting up node-forever-agent (0.5.1-1) ...
Setting up node-mime (1.2.11-1) ...
Setting up node-form-data (0.1.0-1) ...
Setting up node-rimraf (2.2.2-2) ...
Setting up node-mkdirp (0.3.5-1) ...
Setting up node-graceful-fs (2.0.0-2) ...
Setting up node-fstream (0.1.24-1) ...
Setting up node-lru-cache (2.3.1-1) ...
Setting up node-sigmund (1.0.0-1) ...
Setting up node-minimatch (0.2.12-1) ...
Setting up node-fstream-ignore (0.0.6-2) ...
Setting up node-github-url-from-git (1.1.1-1) ...
Setting up node-glob (3.2.6-1) ...
Setting up nodejs-dev (0.10.25~dfsg2-2ubuntu1) ...
Setting up node-nopt (2.1.2-1) ...
Setting up node-npmlog (0.0.4-1) ...
Setting up node-osenv (0.0.3-1) ...
Setting up node-tunnel-agent (0.3.1-1) ...
Setting up node-json-stringify-safe (5.0.0-1) ...
Setting up node-qs (0.6.5-1) ...
Setting up node-request (2.26.1-1) ...
Setting up node-semver (2.1.0-2) ...
Setting up node-tar (0.1.18-1) ...
Setting up node-which (1.0.5-2) ...
Setting up node-gyp (0.10.10-2) ...
Setting up node-ini (1.1.0-1) ...
Setting up node-lockfile (0.4.1-1) ...
Setting up node-mute-stream (0.0.3-1) ...
Setting up node-normalize-package-data (0.2.2-1) ...
Setting up node-once (1.1.1-1) ...
Setting up node-read (1.0.4-1) ...
Setting up node-read-package-json (1.1.3-1) ...
Setting up node-retry (0.6.0-1) ...
Setting up node-sha (1.2.3-1) ...
Setting up node-slide (1.1.4-1) ...
Setting up npm (1.3.10~dfsg-1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
(boot)erp@erp-OptiPlex-330:~/boot/boot/django$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 01, 2015 - 12:32:31
Django version 1.8.3, using settings 'demonstration.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
No comments:
Post a Comment