SPARCS Django Seminar ’django.contrib.staticfiles’, + ‘helloworld’, 40 }...
Transcript of SPARCS Django Seminar ’django.contrib.staticfiles’, + ‘helloworld’, 40 }...
SPARCS Django Seminar by zealot & hood
Part 1
Spotify
ara
PreziNASA
Washington Post
OTLzabo
5
SPARCS Django Seminar by zealot & hood
Part 1
~$ source env/bin/activate
(env) ~$ deactivate # To quit virtualenv (Not now!)8
SPARCS Django Seminar by zealot & hood
Part 1
(env) ~$ pip install django(env) ~$ django-admin startproject sTunes
(env) ~$ cd sTunes(env) ~/sTunes$ lsmanage.py sTunes 9
SPARCS Django Seminar by zealot & hood
Part 1
13
(env) ~/sTunes$ python manage.py startapp helloworld
(env) ~/sTunes$ lshelloworld manage.py tutorial
SPARCS Django Seminar by zealot & hood
Part 1
14
33 INSTALLED_APPS = {…39 ’django.contrib.staticfiles’,+ ‘helloworld’,40 }
~/sTunes/sTunes/settings.py
SPARCS Django Seminar by zealot & hood
Part 1
15
1 from django.shortcuts import render+ from django.http import HttpResponse23 # Create your views here.++++ def helloworld(request):+ return HttpResponse(“Hello, World!”)
~/sTunes/helloworld/views.py
SPARCS Django Seminar by zealot & hood
Part 1
16
19 urlPatterns = [20 url(r’^admin/’, admin.site.urls),+ url(r’^helloworld/$’, ‘helloworld.views.helloworld’),21 ]
~/sTunes/helloworld/urls.py
SPARCS Django Seminar by zealot & hood
Part 1
19 urlPatterns = [20 url(r’^admin/’, admin.site.urls),21 url(r’^helloworld/$’, ‘helloworld.views.helloworld’),+ url(r’^$’, ‘helloworld.views.main’),22 ]
~/sTunes/sTunes/urls.py
8 def helloworld(request):9 return HttpResponse(“Hello, World!”)++++ def main(request):+ return render(request, “main.html”)
~/sTunes/helloworld/views.py 20
SPARCS Django Seminar by zealot & hood
Part 1
56 TEMPLATES = […59 ’DIRS’: [],+ os.path.join(BASE_DIR, ‘templates’)+ ],60 ’OPTIONS’: {
~/sTunes/sTunes/settings.py
22
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h1> Welcome to sTunes! </h1>+ <body>+ </html>
~/sTunes/templates/main.html
23
SPARCS Django Seminar by zealot & hood
Part 1
19 urlPatterns = […22 url(r’^$’, ‘helloworld.views.main’),+ url(r’^artist/IU/$’, ‘helloworld.views.artist_IU’),23 ]
~/sTunes/sTunes/urls.py
13 def main(request):14 return render(request, “main.html”)++++ def artist_IU(request):+ return render(request, “IU.html”)
~/sTunes/helloworld/views.py26
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h2> 아이유 </h2>+ <ul>+ <li> 유형 : 솔로(여성) </li>+ <li> 데뷔 : 2008 </li>+ </ul>+ </br>+ <h4> 출시앨범 </h4>+ <ul>+ <li> Lost And Found </li>+ <li> Real </li>+ <li> 스무 살의 봄 </li>+ <li> CHAT-SHIRE </li>+ <ul>+ </body>+ </html>
~/sTunes/templates/IU.html
27
SPARCS Django Seminar by zealot & hood
Part 1
19 urlPatterns = […23 url(r’^artist/IU/$’, ‘helloworld.views.artist_IU’),+ url(r’^artist/GFRIEND/$’, ‘helloworld.views.artist_GFRIEND’),24 ]
~/sTunes/sTunes/urls.py
18 def artist_IU(request):19 return render(request, “IU.html”)++++ def artist_GFRIEND(request):+ return render(request, “GFRIEND.html”)
~/sTunes/helloworld/views.py30
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h2> 여자친구 </h2>+ <ul>+ <li> 유형 : 그룹(여성) </li>+ <li> 데뷔 : 2015 </li>+ </ul>+ </br>+ <h4> 출시앨범 </h4>+ <ul>+ <li> Season Of Glass </li>+ <li> Flower Bud </li>+ <li> SNOWFLAKE </li>+ <ul>+ </body>+ </html>
~/sTunes/templates/GFRIEND.html
31
SPARCS Django Seminar by zealot & hood
Part 1
19 urlPatterns = […24 url(r’^artist/GFRIEND/$’, ‘helloworld.views.artist_GFRIEND’),+ url(r’^artist/Apink/$’, ‘helloworld.views.artist_Apink’),25 ]
~/sTunes/sTunes/urls.py
23 def artist_GFRIEND(request):24 return render(request, “GFRIEND.html”)++++ def artist_Apink(request):+ return render(request, “Apink.html”)
~/sTunes/helloworld/views.py33
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h2> 에이핑크 </h2>+ <ul>+ <li> 유형 : 그룹(여성) </li>+ <li> 데뷔 : 2011 </li>+ </ul>+ </br>+ <h4> 출시앨범 </h4>+ <ul>+ <li> Seven Springs Of Apink </li>+ <li> Secret Garden </li>+ <li> Pink LUV </li>+ <ul>+ </body>+ </html>
~/sTunes/templates/Apink.html
34
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h2> 에이핑크 </h2>+ <ul>+ <li> 유형 : 그룹(여성) </li>+ <li> 데뷔 : 2011 </li>+ </ul>+ </br>+ <h4> 출시앨범 </h4>+ <ul>+ <li> Seven Springs Of Apink </li>+ <li> Secret Garden </li>+ <li> Pink LUV </li>+ <ul>+ </body>+ </html>
~/sTunes/templates/Apink.html
35
SPARCS Django Seminar by zealot & hood
Part 1
+ <html>+ <head> </head>+ <body>+ <h2> {{ name }} </h2>+ <ul>+ <li> 유형 : {{ type }} </li>+ <li> 데뷔 : {{ debut }} </li>+ </ul>+ </br>+ <h4> 출시앨범 </h4>+ <ul>+ {% for album in albums %}+ <li> {{ album }} </li>+ {% endfor %}+ <ul>+ </body>+ </html>
~/sTunes/templates/artist.html
37
SPARCS Django Seminar by zealot & hood
Part 1
+ # -*- coding: utf-8 -*-1 From django.shortcuts import render…18 def artist_IU(request):+ ctx = {+ “name” : “아이유”,+ “type” : “솔로(여성)”,+ “debut” : 2008,+ “albums” : [“Lost And Found”, “Real”, “스무 살의 봄”, “CHAT-SHIRE”]+ }19 return render(request, “IUartist.html”, ctx)…23 def artist_GFRIEND(request):+ ctx = {+ “name” : “여자친구”,+ “type” : “그룹(여성)”,+ “debut” : 2015,+ “albums” : [“Season Of Glass”, “Flower Bud”, “SNOWFLAKE”]+ }24 return render(request, “GFRIENDartist.html”, ctx)
~/sTunes/helloworld/views.py
38
SPARCS Django Seminar by zealot & hood
Part 1
19 urlPatterns = [20 url(r’^admin/’, admin.site.urls),21 url(r’^helloworld/$’, ‘helloworld.views.helloworld’),22 url(r’^$’, ‘helloworld.views.main’),23 url(r’^artist/IU/$’, ‘helloworld.views.artist_IU’),24 url(r’^artist/GFRIEND/$’, ‘helloworld.views.artist_GFRIEND’),+ url(r’^artist/([\w \[\]\.]+)/$’, ‘helloworld.views.artist’),25 ]
~/sTunes/sTunes/urls.py
40
SPARCS Django Seminar by zealot & hood
Part 1
19 def artist_IU(request):…37 return render(request, “artist.html” , ctx)+ def artist(request, name):+ if name == ”IU”:
ctx = {+ “name” : “아이유”,+ “type” : “솔로(여성)”,+ “debut” : 2008,+ “albums” : [“Lost And Found”, “Real”, “스무 살의 봄”, “CHAT-SHIRE”]+ }+ elif name == “GFRIEND”:+ ctx = {+ “name” : “여자친구”,+ “type” : “그룹(여성)”,+ “debut” : 2015,+ “albums” : [“Season Of Glass”, “Flower Bud”, “SNOWFLAKE”]+ }+ else:+ ctx = {}+ return render(request, “artist.html”, ctx)
~/sTunes/helloworld/views.py
41