반응형
CodingEntrepreneurs Django 강의 정리
path>
urlpatterns 포함할 요소를 반환합니다.
int의 경우 10진수 문자열과 일치하는 경우를 말합니다.
urls.py>
# tweetme2/urls.py
from django.contrib import admin
from django.urls import path
from tweets.views import home_view, tweet_detail_view
urlpatterns = [
path("admin/", admin.site.urls),
path("", home_view),
path("tweets/<int:tweet_id>", tweet_detail_view),
]
models.py>
# tweets/models.py
from django.db import models
# Create your models here.
class Tweet(models.Model):
# Maps to SQL data
# id = models.AutoField(primary_key=True)
content = models.TextField(blank=True, null=True)
image = models.FileField(upload_to="images/", blank=True, null=True)
views.py>
# tweets/views.py
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def home_view(request, *args, **kwargs):
print(args, kwargs)
return HttpResponse("<h1>Hello World</h1>")
def tweet_detail_view(request, tweet_id, *args, **kwargs):
print(args, kwargs)
return HttpResponse(f"<h1>Hello {tweet_id}</h1>")
결과물>
반응형
'Python_WEB > Tweetme' 카테고리의 다른 글
[Django]Dynamic View into REST API Endpoint (0) | 2020.07.01 |
---|---|
[Django]Handling Dynamic Routing (0) | 2020.07.01 |
[Django]The Tweets Model (0) | 2020.06.28 |
[Django]Our Roadmap (0) | 2020.06.28 |
[Django]Setup Django Project (0) | 2020.06.28 |