본문 바로가기

Python_WEB

(190)
[Django]Static Files and Uploading Files CodingEntrepreneurs Django 강의 정리 collectstatic> python manage.py collectstatic 1. 정적 파일을 STATE_ROOT에 수집 가이드 models> from django.conf import settings from django.db import models from django.utils import timezone # Create your models here. User = settings.AUTH_USER_MODEL class BlogPostQuerySet(models.QuerySet): def published(self): now = timezone.now() return self.filter(publish_date__lte=now) cl..
[Django]Published and Draft Posts CodingEntrepreneurs Django 강의 정리 파이프기호> 1. 여러 필터를 지정 2. 하나 이상의 필터를 통해 블록의 내용을 필터링 forms> from django import forms from .models import BlogPost class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) class BlogPostModelForm(forms.ModelForm): # title = forms.CharField() class Meta: model = BlogPost fields = ["title", "slug..
[Django]Model Managers and Custom QuerySets CodingEntrepreneurs Django 강의 정리 get_queryset> 1. 항목 목록 가져오기 2. 쿼리셋 특정 동작을 활성화 models> from django.conf import settings from django.db import models from django.utils import timezone # Create your models here. User = settings.AUTH_USER_MODEL class BlogPostQuerySet(models.QuerySet): def published(self): now = timezone.now() return self.filter(publish_date__lte=now) class BlogPostManager(models.Ma..
[Django]Publish Date, Timestamp & Updated models> from django.conf import settings from django.db import models # Create your models here. User = settings.AUTH_USER_MODEL class BlogPost(models.Model): # blogpost_set > queryset # id = models.IntegerField() # pk user = models.ForeignKey(User, default=1, null=True, on_delete=models.SET_NULL) title = models.CharField(max_length=120) slug = models.SlugField(unique=True) # hello world > hello..
[Django]Include with Arguments CodingEntrepreneurs Django 강의 정리 with> 1. foreign key 관계에서 사용. 첨부된 모든 코멘트를 반복 list-inline.html> {{ blog_post.title }} {{ blog_post.content }} list.html> {% extends "base.html" %} {% block content %} {% for object in object_list %} {% include 'blog/list-inline.html' with blog_post=object %} {% endfor %} {% endblock %} base.html> {% include 'navbar.html' %} {% block content %} {% endblock %} {% in..
[Django]Include the Navbar CodingEntrepreneurs Django 강의 정리 include> 1. 다른 URLconf모듈로 전체 Python가져오기 경로를 사용 가이드 base.html> {% include 'navbar.html' %} {% block content %} {% endblock %} {% include 'js.html' %} js.html> navbar.html> Try Django Home Blog Search
[Django]Blog Post Navigation CodingEntrepreneurs Django 강의 정리 models> from django.conf import settings from django.db import models # Create your models here. User = settings.AUTH_USER_MODEL class BlogPost(models.Model): # blogpost_set > queryset # id = models.IntegerField() # pk user = models.ForeignKey(User, default=1, null=True, on_delete=models.SET_NULL) title = models.CharField(max_length=120) slug = models.SlugField(u..
[Django]Delete and Confirm CodingEntrepreneurs Django 강의 정리 delete.html> {% extends "base.html" %} {% block content %} Are you sure you want to delete the following: {{ object.title }} {% csrf_token %} Yes, Delete {% endblock %} views> from django.contrib.auth.decorators import login_required from django.contrib.admin.views.decorators import staff_member_required from django.http import Http404 from django.shortcuts impor..