Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
15-437 Angular and Django
Search
ThierrySans
February 17, 2016
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
15-437 Angular and Django
ThierrySans
February 17, 2016
More Decks by ThierrySans
See All by ThierrySans
CSCD27 Social Engineering
thierrysans
0
270
CSCD27 Web Security
thierrysans
0
460
CSCD27 Malicious Software
thierrysans
0
410
CSCD27 Protection
thierrysans
0
510
CSCD27 System Insecurity
thierrysans
0
440
CSCD27 Human Authentication
thierrysans
0
370
CSCD27 Network security
thierrysans
0
580
CSCD27 Network (in)security
thierrysans
0
570
CSCD27 Cryptography Protocols
thierrysans
0
730
Other Decks in Programming
See All in Programming
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
yield再入門 #phpcon
o0h
PRO
0
930
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
530
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.7k
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.8k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
480
Android CLI
fornewid
0
210
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
220
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
210
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
440
Featured
See All Featured
Optimizing for Happiness
mojombo
378
71k
Evolving SEO for Evolving Search Engines
ryanjones
0
250
GraphQLとの向き合い方2022年版
quramy
50
15k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Skip the Path - Find Your Career Trail
mkilby
1
180
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
440
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Google's AI Overviews - The New Search
badams
0
1.1k
Transcript
Angular and Django Thierry Sans
Create a project $ django-admin.py startproject webgallery
Summary URLs Served by Django / statically /static/* statically /api/*
dynamically
1. serving / statically
1.1 import index.html webgallery/ manage.py index.html webgallery/ __init__.py settings.py urls.py
wsgi.py
1.2 Configure webgallery/urls.py from django.conf import settings from django.views.static import
server if settings.DEBUG: urlpatterns += [url(r'^(?:index.html)?$', serve, {'path': 'index.html','document_root': settings.BASE_DIR})] webgallery/urls.py
1.3 Test localhost:8000/ You should see your index page But
lot of errors : resources (css, js, …) cannot be found
2. serving /static/* statically
1.1 import all static files in /static/ webgallery/ manage.py
index.html webgallery/ __init__.py settings.py urls.py wsgi.py static/ app/ includes/ media/ style/ ...
2.2 configure settings.py to serve /static/ files webgallery/settings.py #
Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIRS = [os.path.join(BASE_DIR, “static")]
2.3 Test resources You should see resources such as •
localhost:8000/static/style/style.css • localhost:8000/static/app/webgallery.js • ...
2.4 Update your fronted ➡ You should remove all errors
by modifying the path of resources
3. serving /api/* dynamically
3.1 Create an app called api • Create the app
$ python manage.py startapp api • Configure webgallery/settings.py # Application definition INSTALLED_APPS = ( 'django.contrib.admin', ... 'django.contrib.staticfiles', 'api' )
3.2 Configure the url dispatchers • webgallery project URL dispatcher
• api app url dispatcher from django.conf.urls import url from . import views urlpatterns = [ url(r'^helloworld/$', views.helloWorld, name='helloWorld'), url(r'^img/(?P<id>\w+)/$', views.getImgInfo,name='getImgInfo')] api/urls.py webgallery/urls.py from django.conf.urls import include, url urlpatterns += [url(r'^api/', include(‘api’))]
3.3 Write the services from django.shortcuts import render # Create
your views here. from django.http import JsonResponse def helloWorld(request): response = JsonResponse("helloworld",safe=False) return response def getImageInfo(request,id): print id response = JsonResponse(id,safe=False) return response api/views.py
3.5 Test services You should see the services such as
• localhost:8000/api/helloworld/ • localhost:8000/api/img/23/ • ...
4. Complete the API
5. Interface the frontend with the API