300x250
Django 웹페이지 읽기
* 참고 : https://www.youtube.com/watch?v=7ovAmZjDWmk&list=PLuHgQVnccGMDLp4GH-rgQhVKqqZawlNwG&index=7
장고 웹페이지 읽기를 위한 소스코드
* views.py (구성 환경에 따라 소스코드는 달라질 수 있음)
from django.shortcuts import render, HttpResponse
topics = [
{'id': 1, 'title': 'routing', 'body': 'routing is ...'},
{'id': 2, 'title': 'view', 'body': 'view is ...'},
{'id': 3, 'title': 'model', 'body': 'model is ...'}
]
# Create your views here.
def index(request):
global topics
li = ''
for topic in topics:
li += f'<li><a href="/read/{topic["id"]}">{topic["title"]}</a></li>'
return HttpResponse(f'''
<html>
<body>
<h1>Django</h1>
<ol>
{li}
</ol>
</body>
</html>
''')
def create(request):
return HttpResponse("Create!")
def read(request, id): # id 파라미터로 인입
return HttpResponse("Read !!! " + id)
* urls.py (구성 환경에 따라 소스코드는 달라질 수 있음)
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myApp.urls'))
]
장고 실행 결과
반응형
'Python' 카테고리의 다른 글
Python) 파이썬 URL, Base64 인코딩, 디코딩 GUI 구현 (0) | 2022.02.03 |
---|---|
Python) 파이썬 tabWidget (탭위젯) (0) | 2022.02.01 |
Python) 파이썬 Pycharm에서 실행파일 만들기 (0) | 2022.01.16 |
Python) 파이썬 URL, Base64 인코딩 디코딩 (0) | 2022.01.14 |
Python) 파이썬 파일 목록을 CSV로 저장하기 (3) | 2022.01.12 |