Install Django2015/08/01 |
Install Django which is Python Web Application Framework.
|
|
[1] | Install some packages. |
# install from EPEL [root@www ~]# yum --enablerepo=epel -y install python-virtualenv
|
[2] | Install Django under a Virtualenv environment. It's possible to do for any common user. |
[cent@www ~]$ virtualenv venv [cent@www ~]$ cd ~/venv [cent@www venv]$ source bin/activate (venv)[cent@www venv]$ pip install django Downloading/unpacking django Downloading Django-1.8.3.tar.gz (7.3MB): 7.3MB downloaded Running setup.py egg_info for package django warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.py[co]' found under directory '*' Installing collected packages: django Running setup.py install for django warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.py[co]' found under directory '*' changing mode of build/scripts-2.7/django-admin.py from 664 to 775 changing mode of /home/cent/venv/bin/django-admin.py to 775 Installing django-admin script to /home/cent/venv/bin Successfully installed django Cleaning up... # the warning above is not a problem
(venv)[cent@www venv]$
django-admin --version 1.8.3 # exit from virtualenv (venv)[cent@www venv]$ deactivate [cent@www venv]$ |
[3] | Create a test project. |
# create "testproject" (venv)[cent@www venv]$ django-admin startproject testproject (venv)[cent@www venv]$ cd testproject # configure database (default is SQLite) (venv)[cent@www testproject]$ python manage.py migrate
# create admin user (venv)[cent@www testproject]$ python manage.py createsuperuser Username (leave blank to use 'cent'): cent Email address: cent@www.srv.world Password: Password (again): Superuser created successfully. # start server (venv)[cent@www testproject]$ python manage.py runserver 0.0.0.0:8000 Performing system checks... System check identified no issues (0 silenced). August 04, 2015 - 08:09:47 Django version 1.8.3, 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. |
(venv)[cent@www testproject]$ python manage.py startapp testapp
(venv)[cent@www 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)[cent@www testproject]$
mv testproject/urls.py testproject/urls.py.org (venv)[cent@www testproject]$ vi testproject/urls.py # create new from django.conf.urls import patterns, url urlpatterns = patterns('', url(r'^testapp/$', 'testapp.views.main'), )
(venv)[cent@www 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', 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. |
Sponsored Link |
|