Intro django

762 views

Published on

Published in: Education
4 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
762
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
4
Likes
1
Embeds 0
No embeds

No notes for slide

Intro django

  1. 1. Alexander Lyabah: alexander@lyabah.com~$ 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
  2. 2. Что есть в начале?~$ python --versionPython 2.7.3~$ lsb_release -aDistributor ID: UbuntuDescription: Ubuntu 12.10Release: 12.10Codename: quantal
  3. 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-virtualenv0 packages upgraded, 13 newly installed, 0 to remove and 0 notupgraded.[ … ]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$
  4. 4. Installation Django(he)~/envs$ pip install djangoDownloading/unpacking django Downloading Django-1.4.2.tar.gz (7.7Mb): 7.7MbdownloadedInstalling 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...
  5. 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. 6. Runserver – первый запуск(he)~/www/he$ python manage.py runserver 0:8001Validating models...0 errors foundDjango version 1.4.2, using settings he.settingsDevelopment server is running at http://0:8001/Quit the server with CONTROL-C. V0.0
  7. 7. Первый темплейт● get_folder● Первая вьюха● Первый урл● Первый темплей
  8. 8. Settings
  9. 9. Views and URLs
  10. 10. Index.html(he)~/www/he$ mkdir templates
  11. 11. Demo V0.1
  12. 12. Базовый шаблон● base.html● extends● static
  13. 13. Static(he)~/www/he$ mkdir static
  14. 14. base.html
  15. 15. index.html & Demo V0.2
  16. 16. Подключаем Базу Данных● Настройки● Установка postgresql и компонентов для работы с python● requirements.txt
  17. 17. Валера, настало твое время(he)~/www/he$ python manage.py runserver 0:8001Validating models...Unhandled exception in thread started by <bound methodCommand.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", line91, in inner_run self.validate(display_num_errors=True)[ … ] import psycopg2.extensionsImportError: No module named psycopg2.extensions
  18. 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 toprovide /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.obuild/temp.linux-x86_64-2.7/psycopg/typecast.o -lpq -o no previously-included directories found matchingdoc/src/_buildSuccessfully installed psycopg2Cleaning up...
  19. 19. Молодец, Валера! Отличная работа!(he)~/www/he$ python manage.py runserver 0:8001Validating models...0 errors foundDjango version 1.4.2, using settings he.settingsDevelopment 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.cssHTTP/1.1" 200 101265[05/Dec/2012 05:27:16] "GET /static/js/jquery-1.8.3.min.jsHTTP/1.1" 200 93637[05/Dec/2012 05:27:16] "GET /static/js/bootstrap.min.jsHTTP/1.1" 200 25743
  20. 20. 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.txtRequirement 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. 21. PostgeSQL(he)~/www/he$ sudo -upostgres createuser oduvanShall the new role be a superuser? (y/n) y(he)~/www/he$ sudo -upostgres createdb he
  22. 22. Апа● Создание первой апы● Создание новой модели● Настройка админки● PIL● syncdb
  23. 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
  24. 24. Модель
  25. 25. Админка - настройка
  26. 26. Валера? PIL(he)~/www/he$ python manage.py runserver 0:8001Validating models...Unhandled exception in thread started by <bound methodCommand.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, invalidatedjango.core.management.base.CommandError: One or more modelsdid not validate:board.post: "photo": To use ImageFields, you need to installthe Python Imaging Library. Get it athttp://www.pythonware.com/products/pil/ .(he)~/www/he$ pip install pil(he)~/www/he$ pip freeze > requirements.txt
  27. 27. 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_logYou just installed Djangos auth system, which means you donthave any superusers defined.Would you like to create one now? (yes/no): yesUsername (leave blank to use oduvan):E-mail address: alexander@lyabah.comPassword:Password (again):Superuser created successfully.Installing indexes ...Installed 0 object(s) from 0 fixture(s)
  28. 28. Админка добавление V0.3
  29. 29. Demo V0.3
  30. 30. Demo V0.3
  31. 31. Demo V0.3
  32. 32. Demo V0.3
  33. 33. ListView - Выводим посты
  34. 34. Demo V0.4
  35. 35. Авторизация● Контексты● Логин● Логаут● Ексепшен :)● Регистрация● И.... Куча мелких плюшек
  36. 36. Настройки и контекст
  37. 37. URL & Template
  38. 38. Demo V0.5.1
  39. 39. Demo V0.5.1
  40. 40. Demo V0.5.1
  41. 41. Demo V0.5.1
  42. 42. Fix it
  43. 43. Demo V0.5.2
  44. 44. Demo V0.5.2
  45. 45. Registration
  46. 46. Demo V0.5.3
  47. 47. Добавления поста● Url include● Forms● MEDIA
  48. 48. Forms
  49. 49. Views
  50. 50. URLs
  51. 51. Templates of board
  52. 52. Templates of HE
  53. 53. Media(he)~/www/he$ mkdir media
  54. 54. Demo V0.6
  55. 55. Demo V0.6
  56. 56. Demo V0.6
  57. 57. Demo V0.6
  58. 58. Спасибо, Саша!http://www.slideshare.net/AlexanderLyabah/intro-django

×