14. Django

14.1. Instalacja i uruchamianie

$ pip install django

$ django-admin startproject botnet

$ python manage.py migrate

$ python manage.py createsuperuser
Username (leave blank to use 'matt'): admin
Email address: django@astrotech.io
Password:
Password (again):
Superuser created successfully.

$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
June 08, 2017 - 13:33:03
Django version 1.11.2, using settings 'botnet.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

$ cd botnet

$ django-admin startapp heartbeat

Sprawdź w przeglądarce strony:

  • http://127.0.0.1:8000/
  • http://localhost:8000/admin/

14.2. Co to jest Django?

14.3. Architektura aplikacji Django

14.4. Modele

14.5. Widoki

14.6. Panel admina

14.7. Dokumentacja

14.8. Widoki generyczne

14.9. Localization

$ cd botnet/heartbeat
$ mkdir locale

$ django-admin makemessages -l en
processing locale en

$ django-admin makemessages -l pl
processing locale pl

$ django-admin compilemessages
processing file django.po in /private/tmp/botnet/botnet/heartbeat/locale/en/LC_MESSAGES
processing file django.po in /private/tmp/botnet/botnet/heartbeat/locale/pl/LC_MESSAGES

14.10. Sygnały

14.11. Migracje schematów bazy danych

$ python manage.py makemigrations
Migrations for 'heartbeat':
  botnet/heartbeat/migrations/0001_initial.py
    - Create model Heartbeat

$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, heartbeat, sessions
Running migrations:
  Applying heartbeat.0001_initial... OK

14.12. Management Commands

14.13. ORM

14.14. Skrypty z Django

14.15. Przydatne Biblioteki

14.15.1. django-import-export

INSTALLED_APPS.append(‘import_export’)

admin.py:
from import_export.admin import ImportExportModelAdmin

@admin.register(Command)
class CommandAdmin(ImportExportModelAdmin):
    pass

14.15.2. django-grappelli

INSTALLED_APPS.insert(0, ‘grappelli’)