Upload
alexander-lyabah
View
701
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Alexander Lyabah: [email protected]
~$ git clone https://github.com/oduvan/happy-evil.gitCloning into happy-evil...[ … ]Resolving deltas: 100% (38/38), done.
~$ git checkout v0.0git checkout v0.0Note: checking out 'v0.0'. [ … ]HEAD is now at 8bb7a86... initial django
Что есть в начале?
~$ python --versionPython 2.7.3
~$ lsb_release -aDistributor ID: UbuntuDescription: Ubuntu 12.10Release: 12.10Codename: 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 heNew python executable in he/bin/pythonInstalling distribute................done.Installing pip...............done.
~/envs$ source he/bin/activate(he)~/envs$
Installation Django
(he)~/envs$ pip install djangoDownloading/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 775Successfully installed djangoCleaning up...
StartProject – создание проекта
(he)~/envs$ mkdir ~/www(he)~/envs$ cd ~/www/(he)~/www$ django-admin.py startproject he(he)~/www$ lshe(he)~/www$ cd he/(he)~/www/he$ lshe manage.py(he)~/www/he$ ls he/__init__.py settings.py urls.py wsgi.py
Runserver – первый запуск(he)~/www/he$ python manage.py runserver 0:8001Validating models...
0 errors foundDjango 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:8001Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command 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.extensionsImportError: 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 placeProcessing triggers for sgml-base ...Updating the super catalog... (he)~/www/he$ pip install psycopg2Downloading/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 psycopg2Cleaning up...
Молодец, Валера! Отличная работа!
(he)~/www/he$ python manage.py runserver 0:8001Validating models...
0 errors foundDjango 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 freezeDjango==1.4.2argparse==1.2.1distribute==0.6.24psycopg2==2.4.5wsgiref==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 oduvanShall 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:8001Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command 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 validatedjango.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 syncdbCreating tables ...Creating table auth_permissionCreating table auth_group_permissionsCreating table auth_groupCreating table auth_user_user_permissionsCreating table auth_user_groupsCreating table auth_userCreating table django_content_typeCreating table django_sessionCreating table django_siteCreating table board_postCreating 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): yesUsername (leave blank to use 'oduvan'): E-mail address: [email protected]: 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