
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pokoapp.urls'))
]

from django.contrib import admin
from django.urls import path, include
from pokoapp import views
urlpatterns = [
# 사용자가 path가 없는 경로 접속했을 때
path('', views.index),
path('create/', views.create),
path('read/<id>/', views.read)
# <id> : 가변성이 있는 값이 경로에 포함될 경우
topics = [
{'id' : 1, 'title' : 'routing', 'body' : 'Routing is ..'},
{'id' : 2, 'title' : 'view', 'body' : 'View is ..'},
{'id' : 3, 'title' : 'model', 'body' : 'Model is ..'}
]
import random
from django.shortcuts import render, HttpResponse
def index(request):
#return HttpResponse('<h1>Random</h1>'+str(random.random()))
global topics
ol = ''
for topic in topics:
ol += f'<li><a href="/read/{topic["id"]}">{topic["title"]}</a></li>'
return HttpResponse(f'''
<html>
<body>
<h1>Django</h1>
<ol>
{ol}
</ol>
<h2>Welcome</h2>
Hello, Poko
</body>
</html>
''')
def create(request):
return HttpResponse('create!')
def read(request, id):
return HttpResponse('read!'+ id)