전체 글
-
[Python] VSCode에서 Django 템플릿 오토 포매팅하기Python/Django 2021. 12. 13. 14:23
# settings.json "files.associations": { "**/*.html": "html", "**/templates/**/*.html": "django-html", "**/templates/**/*": "django-txt", "**/requirements{/**,*}.{txt,in}": "pip-requirements" }, "emmet.includeLanguages": { "django-html": "html" },
-
[Python] Django Class Based Views 정리 사이트Python/Django 2021. 12. 11. 00:25
Django Class-Based-View Inspector -- Classy CBV What are class-based views anyway? Django's class-based generic views provide abstract classes implementing common web development tasks. These are very powerful, and heavily-utilise Python's object orientation and multiple inheritance in order to be exten ccbv.co.uk
-
[Python] Class Based Views를 사용해보자Python/Django 2021. 12. 11. 00:23
# urls.py from django.urls import path from rooms import views as room_views app_name = "core" urlpatterns = [ path("", room_views.Homeview.as_view(), name="home"), ] # views.py from django.views.generic import ListView from rooms import models as room_models # ListView 외에도 용도에 따라 많은 CBV 들이 존재한다 class Homeview(ListView): """HomeView Definition""" # 모델 지정 model = room_models.Room # 페이지 당 content ..
-
[Python] Django의 Paginator로 쉽게 페이징 해주자Python/Django 2021. 12. 10. 21:50
# views.py from django.shortcuts import render from django.core.paginator import Paginator from rooms import models as room_models def all_rooms(requests): # page라는 query받고, query가 없을 경우 1 page = requests.GET.get("page", 1) """Paginator 써서 구현""" # 사용할 contents room_list = room_models.Room.objects.all() # paginator 설정 (contents_list, 10 == 페이지당 content 갯수) paginator = Paginator(room_list, 10) # n..
-
[Python] shell 명령어를 만들고 사용해보자 (BaseCommand)Python/Django 2021. 12. 9. 23:27
1. App dir 안에 management라는 dir와 __init__.py를 만든다. 2. 그안에 commands라는 dir와 __init__.py를 만든다 3. 그안에 사용할 명령어로된 이름의 파이썬 파일을 만든다 예) python manage.py seed_rooms = rooms.management.commands.seed_rooms.py # seed_rooms.py import random # BaseCommand 이거 필수! from django.core.management.base import BaseCommand from django_seed import Seed from rooms import models as room_models from users import models as us..
-
[Python] admin안에 admin을 넣어보자 (TabularInline, inlines)Python/Django 2021. 12. 8. 16:05
# admin.py class PhotoInline(admin.TabularInline): """Photo Inline Definition""" model = models.Photo classes = ["collapse"] @admin.register(models.Room) class RoomAdmin(admin.ModelAdmin): """Room Admin Definition""" inlines = (PhotoInline,)
-
[Python] tag return 하기Python/Django 2021. 12. 8. 15:03
# admin.py from django.contrib import admin from django.utils.html import mark_safe from . import models @admin.register(models.Photo) class PhotoAdmin(admin.ModelAdmin): """Photo Admin Definition""" list_display = [ "__str__", "get_thumbnail", ] def get_thumbnail(self, obj): print(dir(obj.file)) return mark_safe(f"") get_thumbnail.short_description = "Thumbnail" 장고는 기본적으로 해킹이나 예상치 못한 tag input ..