SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
Alexander Lyabah:   alexander@lyabah.com

~$ git clone https://github.com/oduvan/happy-evil.git
Cloning into happy-evil...
[ … ]
Resolving deltas: 100% (38/38), done.

~$ git checkout v0.0
git checkout v0.0
Note: checking out 'v0.0'.
 [ … ]
HEAD is now at 8bb7a86... initial django
Что есть в начале?

~$ python --version
Python 2.7.3




~$ lsb_release -a
Distributor ID:   Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
Installation VirtualEnv
~$ sudo aptitude install python-virtualenv
[sudo] password for oduvan:
The following NEW packages will be installed:
  [ … ] python-pip{a} python-setuptools{a} python-virtualenv
0 packages upgraded, 13 newly installed, 0 to remove and 0 not
upgraded.
[ … ]
Setting up build-essential (11.5ubuntu3) ...
~$ cd envs/
~/envs$ virtualenv he
New python executable in he/bin/python
Installing distribute................done.
Installing pip...............done.

~/envs$ source he/bin/activate
(he)~/envs$
Installation Django
(he)~/envs$ pip install django
Downloading/unpacking django
  Downloading Django-1.4.2.tar.gz (7.7Mb): 7.7Mb
downloaded

Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-2.7/django-
admin.py from 664 to 775

    changing mode of
/home/oduvan/envs/he/bin/django-admin.py to 775
Successfully installed django
Cleaning up...
StartProject – создание проекта
 (he)~/envs$ mkdir ~/www
 (he)~/envs$ cd ~/www/
 (he)~/www$ django-admin.py startproject he
 (he)~/www$ ls
 he
 (he)~/www$ cd he/
 (he)~/www/he$ ls
 he manage.py
 (he)~/www/he$ ls he/
 __init__.py settings.py urls.py wsgi.py
Runserver – первый запуск
(he)~/www/he$ python manage.py runserver 0:8001
Validating models...

0 errors found
Django version 1.4.2, using settings 'he.settings'
Development server is running at http://0:8001/
Quit the server with CONTROL-C.




                                                     V0.0
Первый темплейт
●   get_folder
●   Первая вьюха
●   Первый урл
●   Первый темплей
Settings
Views and URLs
Index.html
(he)~/www/he$ mkdir templates
Demo




       V0.1
Базовый шаблон
●   base.html
●   extends
●   static
Static
(he)~/www/he$ mkdir static
base.html
index.html & Demo




                    V0.2
Подключаем Базу Данных
●   Настройки
●   Установка postgresql и компонентов для
    работы с python
●   requirements.txt
Валера, настало твое время



(he)~/www/he$ python manage.py   runserver 0:8001
Validating models...

Unhandled exception in thread started by <bound method
Command.inner_run of
<django.contrib.staticfiles.management.commands.runserver.Co
mmand object at 0x235be90>>
Traceback (most recent call last):
  File "/home/oduvan/envs/he/local/lib/python2.7/site-
packages/django/core/management/commands/runserver.py", line
91, in inner_run
    self.validate(display_num_errors=True)
[ … ]
    import psycopg2.extensions
ImportError: No module named psycopg2.extensions
Ад ( … миним … )
(he)~/www/he$ sudo aptitude install postgresql libpq-
dev python-dev
[ … ]
Configuring postgresql.conf to use port 5432...
update-alternatives: using
/usr/share/postgresql/9.1/man/man1/postmaster.1.gz to
provide /usr/share/man/man1/postmaster.1.gz
(postmaster.1.gz) in auto mode
 * Starting PostgreSQL 9.1 database server [ OK ]
Setting up postgresql (9.1+136) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for sgml-base ...
Updating the super catalog...
(he)~/www/he$ pip install psycopg2
Downloading/unpacking psycopg2
[ … ]
/temp.linux-x86_64-2.7/psycopg/microprotocols_proto.o
build/temp.linux-x86_64-2.7/psycopg/typecast.o -lpq -o
    no previously-included directories found matching
'doc/src/_build'
Successfully installed psycopg2
Cleaning up...
Молодец, Валера! Отличная
         работа!
(he)~/www/he$ python manage.py   runserver 0:8001
Validating models...

0 errors found
Django version 1.4.2, using settings 'he.settings'
Development server is running at http://0:8001/
Quit the server with CONTROL-C.
[05/Dec/2012 05:27:15] "GET / HTTP/1.1" 200 1183
[05/Dec/2012 05:27:16] "GET /static/css/bootstrap.min.css
HTTP/1.1" 200 101265
[05/Dec/2012 05:27:16] "GET /static/js/jquery-1.8.3.min.js
HTTP/1.1" 200 93637
[05/Dec/2012 05:27:16] "GET /static/js/bootstrap.min.js
HTTP/1.1" 200 25743
pip freeze
(he)~/www/he$ pip freeze
Django==1.4.2
argparse==1.2.1
distribute==0.6.24
psycopg2==2.4.5
wsgiref==0.1.2


(he)~/www/he$ pip freeze > requirements.txt
(he)~/www/he$ pip install -r requirements.txt
Requirement already satisfied (use --upgrade to upgrade):
Django==1.4.2 in /home/oduvan/envs/he/lib/python2.7/site-
packages (from -r requirements.txt (line 1))
[ … ]
Requirement already satisfied (use --upgrade to upgrade):
psycopg2==2.4.5 in /home/oduvan/envs/he/lib/python2.7/site-
packages (from -r requirements.txt (line 4))
Requirement already satisfied (use --upgrade to upgrade):
wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt
(line 5))
Cleaning up...
PostgeSQL

(he)~/www/he$ sudo -upostgres createuser oduvan
Shall the new role be a superuser? (y/n) y
(he)~/www/he$ sudo -upostgres createdb he
Апа
●   Создание первой апы
●   Создание новой модели
●   Настройка админки
●   PIL
●   syncdb
Создаем и настраиваем
(he)~/www/he$ mkdir apps
(he)~/www/he$ cd apps/
(he)~/www/he/apps$ django-admin.py startapp board
(he)~/www/he/apps$ ls board/
__init__.py models.py tests.py views.py
Модель
Админка - настройка
Валера? PIL
(he)~/www/he$ python manage.py runserver 0:8001
Validating models...

Unhandled exception in thread started by <bound method
Command.inner_run of
<django.contrib.staticfiles.management.commands.runserver.Comm
and object at 0x2668f10>>
Traceback (most recent call last):
  [ … ]
  File "/home/oduvan/envs/he/local/lib/python2.7/site-
packages/django/core/management/base.py", line 270, in
validate
django.core.management.base.CommandError: One or more models
did not validate:
board.post: "photo": To use ImageFields, you need to install
the Python Imaging Library. Get it at
http://www.pythonware.com/products/pil/ .

(he)~/www/he$ pip install pil
(he)~/www/he$ pip freeze > requirements.txt
Syncdb
(he)oduvan@ubuntuServer12:~/www/he$ python manage.py   syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table board_post
Creating table django_admin_log

You just installed Django's auth system, which means you don't
have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'oduvan'):
E-mail address: alexander@lyabah.com
Password:
Password (again):
Superuser created successfully.
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Админка добавление




                     V0.3
Demo




       V0.3
Demo




       V0.3
Demo




       V0.3
Demo




       V0.3
ListView - Выводим посты
Demo




       V0.4
Авторизация
●   Контексты
●   Логин
●   Логаут
●   Ексепшен :)
●   Регистрация
●   И.... Куча мелких плюшек
Настройки и контекст
URL & Template
Demo




       V0.5.1
Demo




       V0.5.1
Demo




       V0.5.1
Demo




       V0.5.1
Fix it
Demo




       V0.5.2
Demo




       V0.5.2
Registration
Demo




       V0.5.3
Добавления поста
●   Url include
●   Forms
●   MEDIA
Forms
Views
URLs
Templates of board
Templates of HE
Media
(he)~/www/he$ mkdir media
Demo




       V0.6
Demo




       V0.6
Demo




       V0.6
Demo




       V0.6
Спасибо, Саша!
http://www.slideshare.net/AlexanderLyabah/intro-django

Contenu connexe

Tendances

Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 
Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册
Yiwei Ma
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
Ryosuke IWANAGA
 

Tendances (20)

Ubic
UbicUbic
Ubic
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
EC2
EC2EC2
EC2
 
Puppet control-repo 
to the next level
Puppet control-repo 
to the next levelPuppet control-repo 
to the next level
Puppet control-repo 
to the next level
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...
Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...
Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...
 
(Practical) linux 101
(Practical) linux 101(Practical) linux 101
(Practical) linux 101
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menu
 
Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册
 
Odoo V8 Installation
Odoo V8 InstallationOdoo V8 Installation
Odoo V8 Installation
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
How to Install Odoo 11 on Ubuntu 16.04?
How to Install Odoo 11 on Ubuntu 16.04?How to Install Odoo 11 on Ubuntu 16.04?
How to Install Odoo 11 on Ubuntu 16.04?
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011
 
Nginx2
Nginx2Nginx2
Nginx2
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
 

En vedette

Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
Christine Cheung
 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & Django
Allan Mangune
 

En vedette (15)

LCNUG 2015 - what's new for agile teams in TFS 2015
LCNUG 2015 -  what's new for agile teams in TFS 2015LCNUG 2015 -  what's new for agile teams in TFS 2015
LCNUG 2015 - what's new for agile teams in TFS 2015
 
Dev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldDev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps World
 
Django Multi-DB in Anger
Django Multi-DB in AngerDjango Multi-DB in Anger
Django Multi-DB in Anger
 
Why Django
Why DjangoWhy Django
Why Django
 
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
 
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
 
Multi Tenancy With Python and Django
Multi Tenancy With Python and DjangoMulti Tenancy With Python and Django
Multi Tenancy With Python and Django
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & Django
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 
Global Windows Azure Bootcamp : Pierre-Yves Fare Mobile Services. (sponsor An...
Global Windows Azure Bootcamp : Pierre-Yves Fare Mobile Services. (sponsor An...Global Windows Azure Bootcamp : Pierre-Yves Fare Mobile Services. (sponsor An...
Global Windows Azure Bootcamp : Pierre-Yves Fare Mobile Services. (sponsor An...
 

Similaire à Intro django

Similaire à Intro django (20)

DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Docker practice
Docker practiceDocker practice
Docker practice
 
Os dev tool box
Os dev tool boxOs dev tool box
Os dev tool box
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in Ruby
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 

Dernier

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Intro django

  • 1. Alexander Lyabah: alexander@lyabah.com ~$ git clone https://github.com/oduvan/happy-evil.git Cloning into happy-evil... [ … ] Resolving deltas: 100% (38/38), done. ~$ git checkout v0.0 git checkout v0.0 Note: checking out 'v0.0'. [ … ] HEAD is now at 8bb7a86... initial django
  • 2. Что есть в начале? ~$ python --version Python 2.7.3 ~$ lsb_release -a Distributor ID: Ubuntu Description: Ubuntu 12.10 Release: 12.10 Codename: quantal
  • 3. Installation VirtualEnv ~$ sudo aptitude install python-virtualenv [sudo] password for oduvan: The following NEW packages will be installed: [ … ] python-pip{a} python-setuptools{a} python-virtualenv 0 packages upgraded, 13 newly installed, 0 to remove and 0 not upgraded. [ … ] Setting up build-essential (11.5ubuntu3) ... ~$ cd envs/ ~/envs$ virtualenv he New python executable in he/bin/python Installing distribute................done. Installing pip...............done. ~/envs$ source he/bin/activate (he)~/envs$
  • 4. Installation Django (he)~/envs$ pip install django Downloading/unpacking django Downloading Django-1.4.2.tar.gz (7.7Mb): 7.7Mb downloaded Installing collected packages: django Running setup.py install for django changing mode of build/scripts-2.7/django- admin.py from 664 to 775 changing mode of /home/oduvan/envs/he/bin/django-admin.py to 775 Successfully installed django Cleaning up...
  • 5. StartProject – создание проекта (he)~/envs$ mkdir ~/www (he)~/envs$ cd ~/www/ (he)~/www$ django-admin.py startproject he (he)~/www$ ls he (he)~/www$ cd he/ (he)~/www/he$ ls he manage.py (he)~/www/he$ ls he/ __init__.py settings.py urls.py wsgi.py
  • 6. Runserver – первый запуск (he)~/www/he$ python manage.py runserver 0:8001 Validating models... 0 errors found Django version 1.4.2, using settings 'he.settings' Development server is running at http://0:8001/ Quit the server with CONTROL-C. V0.0
  • 7. Первый темплейт ● get_folder ● Первая вьюха ● Первый урл ● Первый темплей
  • 11. Demo V0.1
  • 12. Базовый шаблон ● base.html ● extends ● static
  • 16. Подключаем Базу Данных ● Настройки ● Установка postgresql и компонентов для работы с python ● requirements.txt
  • 17. Валера, настало твое время (he)~/www/he$ python manage.py runserver 0:8001 Validating models... Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Co mmand object at 0x235be90>> Traceback (most recent call last): File "/home/oduvan/envs/he/local/lib/python2.7/site- packages/django/core/management/commands/runserver.py", line 91, in inner_run self.validate(display_num_errors=True) [ … ] import psycopg2.extensions ImportError: No module named psycopg2.extensions
  • 18. Ад ( … миним … ) (he)~/www/he$ sudo aptitude install postgresql libpq- dev python-dev [ … ] Configuring postgresql.conf to use port 5432... update-alternatives: using /usr/share/postgresql/9.1/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode * Starting PostgreSQL 9.1 database server [ OK ] Setting up postgresql (9.1+136) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place Processing triggers for sgml-base ... Updating the super catalog... (he)~/www/he$ pip install psycopg2 Downloading/unpacking psycopg2 [ … ] /temp.linux-x86_64-2.7/psycopg/microprotocols_proto.o build/temp.linux-x86_64-2.7/psycopg/typecast.o -lpq -o no previously-included directories found matching 'doc/src/_build' Successfully installed psycopg2 Cleaning up...
  • 19. Молодец, Валера! Отличная работа! (he)~/www/he$ python manage.py runserver 0:8001 Validating models... 0 errors found Django version 1.4.2, using settings 'he.settings' Development server is running at http://0:8001/ Quit the server with CONTROL-C. [05/Dec/2012 05:27:15] "GET / HTTP/1.1" 200 1183 [05/Dec/2012 05:27:16] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 101265 [05/Dec/2012 05:27:16] "GET /static/js/jquery-1.8.3.min.js HTTP/1.1" 200 93637 [05/Dec/2012 05:27:16] "GET /static/js/bootstrap.min.js HTTP/1.1" 200 25743
  • 20. pip freeze (he)~/www/he$ pip freeze Django==1.4.2 argparse==1.2.1 distribute==0.6.24 psycopg2==2.4.5 wsgiref==0.1.2 (he)~/www/he$ pip freeze > requirements.txt (he)~/www/he$ pip install -r requirements.txt Requirement already satisfied (use --upgrade to upgrade): Django==1.4.2 in /home/oduvan/envs/he/lib/python2.7/site- packages (from -r requirements.txt (line 1)) [ … ] Requirement already satisfied (use --upgrade to upgrade): psycopg2==2.4.5 in /home/oduvan/envs/he/lib/python2.7/site- packages (from -r requirements.txt (line 4)) Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt (line 5)) Cleaning up...
  • 21. PostgeSQL (he)~/www/he$ sudo -upostgres createuser oduvan Shall the new role be a superuser? (y/n) y (he)~/www/he$ sudo -upostgres createdb he
  • 22. Апа ● Создание первой апы ● Создание новой модели ● Настройка админки ● PIL ● syncdb
  • 23. Создаем и настраиваем (he)~/www/he$ mkdir apps (he)~/www/he$ cd apps/ (he)~/www/he/apps$ django-admin.py startapp board (he)~/www/he/apps$ ls board/ __init__.py models.py tests.py views.py
  • 26. Валера? PIL (he)~/www/he$ python manage.py runserver 0:8001 Validating models... Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Comm and object at 0x2668f10>> Traceback (most recent call last): [ … ] File "/home/oduvan/envs/he/local/lib/python2.7/site- packages/django/core/management/base.py", line 270, in validate django.core.management.base.CommandError: One or more models did not validate: board.post: "photo": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ . (he)~/www/he$ pip install pil (he)~/www/he$ pip freeze > requirements.txt
  • 27. Syncdb (he)oduvan@ubuntuServer12:~/www/he$ python manage.py syncdb Creating tables ... Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_user_permissions Creating table auth_user_groups Creating table auth_user Creating table django_content_type Creating table django_session Creating table django_site Creating table board_post Creating table django_admin_log You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (leave blank to use 'oduvan'): E-mail address: alexander@lyabah.com Password: Password (again): Superuser created successfully. Installing indexes ... Installed 0 object(s) from 0 fixture(s)
  • 29. Demo V0.3
  • 30. Demo V0.3
  • 31. Demo V0.3
  • 32. Demo V0.3
  • 34. Demo V0.4
  • 35. Авторизация ● Контексты ● Логин ● Логаут ● Ексепшен :) ● Регистрация ● И.... Куча мелких плюшек
  • 38. Demo V0.5.1
  • 39. Demo V0.5.1
  • 40. Demo V0.5.1
  • 41. Demo V0.5.1
  • 43. Demo V0.5.2
  • 44. Demo V0.5.2
  • 46. Demo V0.5.3
  • 47. Добавления поста ● Url include ● Forms ● MEDIA
  • 48. Forms
  • 49. Views
  • 50. URLs
  • 54. Demo V0.6
  • 55. Demo V0.6
  • 56. Demo V0.6
  • 57. Demo V0.6