From 48a2395009da5b18563ede7c032c41adf099629c Mon Sep 17 00:00:00 2001 From: Jin Park Date: Wed, 11 Nov 2015 20:31:58 +0900 Subject: [PATCH 1/2] first pass at django lesson 4 --- .gitignore | 1 + lesson_4/htmlcss.md | 0 lesson_4/restaurants.md | 0 .../solutions/restaurants/best/__init__.py | 0 lesson_4/solutions/restaurants/best/admin.py | 3 + .../restaurants/best/migrations/__init__.py | 0 lesson_4/solutions/restaurants/best/models.py | 3 + .../best/templates/best/index.html | 3 + lesson_4/solutions/restaurants/best/tests.py | 3 + lesson_4/solutions/restaurants/best/urls.py | 6 + lesson_4/solutions/restaurants/best/views.py | 14 +++ lesson_4/solutions/restaurants/db.sqlite3 | Bin 0 -> 12288 bytes lesson_4/solutions/restaurants/manage.py | 10 ++ .../restaurants/restaurants/__init__.py | 0 .../restaurants/restaurants/settings.py | 103 ++++++++++++++++++ .../solutions/restaurants/restaurants/urls.py | 22 ++++ .../solutions/restaurants/restaurants/wsgi.py | 16 +++ 17 files changed, 184 insertions(+) create mode 100644 lesson_4/htmlcss.md create mode 100644 lesson_4/restaurants.md create mode 100644 lesson_4/solutions/restaurants/best/__init__.py create mode 100644 lesson_4/solutions/restaurants/best/admin.py create mode 100644 lesson_4/solutions/restaurants/best/migrations/__init__.py create mode 100644 lesson_4/solutions/restaurants/best/models.py create mode 100644 lesson_4/solutions/restaurants/best/templates/best/index.html create mode 100644 lesson_4/solutions/restaurants/best/tests.py create mode 100644 lesson_4/solutions/restaurants/best/urls.py create mode 100644 lesson_4/solutions/restaurants/best/views.py create mode 100644 lesson_4/solutions/restaurants/db.sqlite3 create mode 100755 lesson_4/solutions/restaurants/manage.py create mode 100644 lesson_4/solutions/restaurants/restaurants/__init__.py create mode 100644 lesson_4/solutions/restaurants/restaurants/settings.py create mode 100644 lesson_4/solutions/restaurants/restaurants/urls.py create mode 100644 lesson_4/solutions/restaurants/restaurants/wsgi.py diff --git a/.gitignore b/.gitignore index e43b0f9..dde3895 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +*.pyc diff --git a/lesson_4/htmlcss.md b/lesson_4/htmlcss.md new file mode 100644 index 0000000..e69de29 diff --git a/lesson_4/restaurants.md b/lesson_4/restaurants.md new file mode 100644 index 0000000..e69de29 diff --git a/lesson_4/solutions/restaurants/best/__init__.py b/lesson_4/solutions/restaurants/best/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lesson_4/solutions/restaurants/best/admin.py b/lesson_4/solutions/restaurants/best/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/lesson_4/solutions/restaurants/best/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/lesson_4/solutions/restaurants/best/migrations/__init__.py b/lesson_4/solutions/restaurants/best/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lesson_4/solutions/restaurants/best/models.py b/lesson_4/solutions/restaurants/best/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/lesson_4/solutions/restaurants/best/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/lesson_4/solutions/restaurants/best/templates/best/index.html b/lesson_4/solutions/restaurants/best/templates/best/index.html new file mode 100644 index 0000000..690c956 --- /dev/null +++ b/lesson_4/solutions/restaurants/best/templates/best/index.html @@ -0,0 +1,3 @@ +{% for resto in restaurants %} +

{{resto.name}}

+{% endfor %} diff --git a/lesson_4/solutions/restaurants/best/tests.py b/lesson_4/solutions/restaurants/best/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/lesson_4/solutions/restaurants/best/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/lesson_4/solutions/restaurants/best/urls.py b/lesson_4/solutions/restaurants/best/urls.py new file mode 100644 index 0000000..494f0d7 --- /dev/null +++ b/lesson_4/solutions/restaurants/best/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import include, url +from . import views + +urlpatterns = [ + url(r'^$', views.list, name='list'), +] diff --git a/lesson_4/solutions/restaurants/best/views.py b/lesson_4/solutions/restaurants/best/views.py new file mode 100644 index 0000000..e99af2d --- /dev/null +++ b/lesson_4/solutions/restaurants/best/views.py @@ -0,0 +1,14 @@ +from django.shortcuts import render + +def list(request): + restaurants = [{ + "name": "mcdonalds", + "price": "$", + "review": "its ok" + }, + { + "name": "burger king", + "price": "$$", + "review": "flame grilled burgers!" + }] + return render(request, 'best/index.html', {"restaurants": restaurants}) diff --git a/lesson_4/solutions/restaurants/db.sqlite3 b/lesson_4/solutions/restaurants/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..748753cb4fb86e07aecd037c242dcb317d7c9ccb GIT binary patch literal 12288 zcmeI#yH3L}6b4{B5!>1jR{7%w5iJukH|yt95{$p zq7`Ccs{SK6)`@+bh--*Ot*ea-Z&ccLUU5z52H5OVm7nsMO4!#Q8^dg zuDdQXi}kzyzG_M{CCvj9p`}*2T$j3aZ*H1?1Oy-e0SG_<0uX=z1Rwwb2tWV=J1l_y ee}{iAJ`Dm8fB*y_009U<00Izz00bcLE$|5uyK7DW literal 0 HcmV?d00001 diff --git a/lesson_4/solutions/restaurants/manage.py b/lesson_4/solutions/restaurants/manage.py new file mode 100755 index 0000000..92862db --- /dev/null +++ b/lesson_4/solutions/restaurants/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "restaurants.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/lesson_4/solutions/restaurants/restaurants/__init__.py b/lesson_4/solutions/restaurants/restaurants/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lesson_4/solutions/restaurants/restaurants/settings.py b/lesson_4/solutions/restaurants/restaurants/settings.py new file mode 100644 index 0000000..3e6f6f4 --- /dev/null +++ b/lesson_4/solutions/restaurants/restaurants/settings.py @@ -0,0 +1,103 @@ +""" +Django settings for restaurants project. + +Generated by 'django-admin startproject' using Django 1.8.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'ejmf_c7$h@ew=i6pwx#xi)rxc7uh=_m2aarz)xcvh$mw(4i82+' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'best' +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'restaurants.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'restaurants.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/lesson_4/solutions/restaurants/restaurants/urls.py b/lesson_4/solutions/restaurants/restaurants/urls.py new file mode 100644 index 0000000..0363ad1 --- /dev/null +++ b/lesson_4/solutions/restaurants/restaurants/urls.py @@ -0,0 +1,22 @@ +"""restaurants URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) +""" +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^best/', include('best.urls')), + url(r'^admin/', include(admin.site.urls)), +] diff --git a/lesson_4/solutions/restaurants/restaurants/wsgi.py b/lesson_4/solutions/restaurants/restaurants/wsgi.py new file mode 100644 index 0000000..c123afd --- /dev/null +++ b/lesson_4/solutions/restaurants/restaurants/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for restaurants project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "restaurants.settings") + +application = get_wsgi_application() From 860320ee6a88dbc77f7e92007eee7dc59026af03 Mon Sep 17 00:00:00 2001 From: Jin Park Date: Wed, 11 Nov 2015 20:35:13 +0900 Subject: [PATCH 2/2] add intro instructions --- lesson_4/restaurants.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lesson_4/restaurants.md b/lesson_4/restaurants.md index e69de29..b8de9ba 100644 --- a/lesson_4/restaurants.md +++ b/lesson_4/restaurants.md @@ -0,0 +1,17 @@ +Making a simple restaurants review app +--- + +Requirements: +- Python 3+ and Django 1.8+ installed + +1. Make a new folder +2. Create a new virtualenv and activate it +3. `pip install django` +4. `django-admin startproject restaurants` +5. `django-admin startapp best` +6. Make a list of restaurants with its features in a dictionary +7. Create a template in `best/templates/best/index.py` +8. Create a `urls.py` for `best` app +9. Link `best` `urls.py` with `restaurants` `urls.py` +10. `python manage.py runserver` +11. Go to `localhost:8000/best`