15. Django

15.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/

15.2. Co to jest Django?

15.3. Architektura aplikacji Django

15.4. Modele

15.5. Widoki

15.6. Panel admina

15.7. Dokumentacja

15.8. Widoki generyczne

15.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

15.10. Sygnały

15.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

15.12. Management Commands

15.13. ORM

15.14. Skrypty z Django

15.15. Przydatne Biblioteki

15.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

15.15.2. django-grappelli

INSTALLED_APPS.insert(0, ‘grappelli’)