Ubuntu 14.04
Sponsored Link

Install Django2016/01/26

 
Install Django which is Python Web Application Framework.
[1] Install some packages.
root@www:~#
apt-get -y install python-virtualenv
[2] Install Django under a Virtualenv environment. It's possible to do for any common user.
ubuntu@www:~$
virtualenv venv

ubuntu@www:~$
cd ~/venv

ubuntu@www:~/venv$
source bin/activate

(venv)ubuntu@www:~/venv$
pip install -U pip

(venv)ubuntu@www:~/venv$
pip install django

Collecting django
/home/ubuntu/venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:315: 
  SNIMissingWarning:   An HTTPS request has been made, but the SNI (Subject Name Indication) extension to 
  TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, 
  which can cause validation failures. For more information, 
  see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/ubuntu/venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: 
   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
  Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
    100% |###############################| 6.6MB 66kB/s
Installing collected packages: django
Successfully installed django-1.9.1

(venv)ubuntu@www:~/venv$
django-admin --version

1.9.1
# exit from virtualenv

(venv)ubuntu@www:~/venv$
deactivate

ubuntu@www:~/venv$
[3] Create a test project.
ubuntu@www:~$
cd ~/venv

ubuntu@www:~/venv$
source bin/activate
# create "testproject"

(venv)ubuntu@www:~/venv$
django-admin startproject testproject

(venv)ubuntu@www:~/venv$
cd testproject

# configure database (default is SQLite)

(venv)ubuntu@www:~/venv/testproject$
python manage.py migrate
# create admin user

(venv)ubuntu@www:~/venv/testproject$
python manage.py createsuperuser

Username (leave blank to use 'ubuntu'):
ubuntu

Email address:
ubuntu@www.srv.world

Password:
Password (again):
Superuser created successfully.
# start server

venv)ubuntu@www:~/venv/testproject$
python manage.py runserver 0.0.0.0:8000

Performing system checks...

System check identified no issues (0 silenced).
January 27, 2016 - 07:37:09
Django version 1.9.1, using settings 'testproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[4] Access to the "http://(server's hostname or IP address):8000/" from a client computer. It's OK if following site is displayed normally.
[5] It's possible to user admin site on "http://(server's hostname or IP address):8000/admin".
[6] Create a test application.
ubuntu@www:~$
cd ~/venv

ubuntu@www:~/venv$
source bin/activate

(venv)ubuntu@www:~/venv$
cd testproject

(venv)ubuntu@www:~/venv/testproject$
python manage.py startapp testapp

(venv)ubuntu@www:~/venv/testproject$
vi testapp/views.py
# add to the end

from django.http import HttpResponse
def main(request):
    html = '<html>\n' \
           '<body>\n' \
           '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \
           'Django Test Page\n' \
           '</div>\n' \
           '</body>\n' \
           '</html>\n'
    return HttpResponse(html)

(venv)ubuntu@www:~/venv/testproject$
mv testproject/urls.py testproject/urls.py.org

(venv)ubuntu@www:~/venv/testproject$
vi testproject/urls.py
# create new

from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^testapp/$', 'testapp.views.main'),
)

(venv)ubuntu@www:~/venv/testproject$
vi testproject/settings.py
# add testapp

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'testapp',
)
(venv)ubuntu@www:~/venv/testproject$
python manage.py runserver 0.0.0.0:8000

[7] Access to the "http://(server's hostname or IP address):8000/testapp/" from a client computer. It's OK if testapp is displayed normally.
Matched Content