Successfully reported this slideshow.
Your SlideShare is downloading. ×

Django osc2018-okinawa

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 56 Ad

More Related Content

Slideshows for you (20)

Similar to Django osc2018-okinawa (20)

Advertisement

More from Xoxzo Inc. (20)

Recently uploaded (20)

Advertisement

Django osc2018-okinawa

  1. 1. Django Akira Nonaka 2018.06.16 • OSC Okinawa
  2. 2. About Me • XOXZO( ) • Python
  3. 3. About XOXZO • API • SMS & • Web Django
  4. 4. Contents 1. Django 2. 3. Django 4.
  5. 5. $ python --version Python 3.6.0 $ python -m venv myvenv $ source myvenv/bin/activate (myvenv) $ pip install django Collecting django…
  6. 6. $ pip list Package Version ---------- ------- Django 2.0.6 pip 10.0.1 pytz 2018.4 setuptools 28.8.0
  7. 7. $ django-admin startproject mysite $ tree mysite/ mysite/ !"" manage.py #"" mysite !"" __init__.py !"" settings.py !"" urls.py #"" wsgi.py
  8. 8. $ cat manage.py #!/usr/bin/env python import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv)
  9. 9. $ ./manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. June 10, 2018 - 08:07:07 Django version 2.0.6, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [10/Jun/2018 08:07:44] "GET / HTTP/1.1" 200 16348 [10/Jun/2018 08:07:44] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423 [10/Jun/2018 08:07:44] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/ 1.1" 200 81348 [10/Jun/2018 08:07:44] "GET /static/admin/fonts/Roboto-Regular-webfont.woff
  10. 10. ROOT_URLCONF = 'mysite.urls'
  11. 11. $ cat mysite/urls.py """mysite URL Configuration ( …) """ from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), ]
  12. 12.
  13. 13. # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }
  14. 14. $ ./manage.py startapp polls $ tree polls/ polls/ !"" __init__.py !"" admin.py !"" apps.py !"" migrations $   #"" __init__.py !"" models.py !"" tests.py #"" views.py
  15. 15. urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls), ]
  16. 16. from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), ]
  17. 17. from django.http import HttpResponse def index(request): return HttpResponse("Hello, Okinawa. You're at the polls index.")
  18. 18. 
 
 

  19. 19. $ ./manage.py makemigrations Migrations for 'polls': polls/migrations/0001_initial.py - Create model Question
  20. 20. $ ./manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, polls, sessions Running migrations: Applying polls.0001_initial... OK
  21. 21. class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Question', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('question_text', models.CharField(max_length=200)), ('pub_date', models.DateTimeField(verbose_name='date published')), ], ), ]
  22. 22. 
 
 
 
 


×