한글 출력 기본 원칙 인코딩과 디코딩할 때 chatset 을 맞춰서 해야함 보통 jsp파일에 바로 한글 쓰는 것은 문제되지 않음 디렉티브 태그 setContentType과 pageEncoding에서 인코딩과 디코딩을 처리해줌 그러나 url로 넘기거나 request로 다른 jsp파일로 값을 넘기는 경우에는 다름 인코딩과 디코딩을 직접 지정해줘야함 Base64 java.util.Base64 response.sendRedirect("main.jsp?name="+Base64.getEncoder().encodeToString("홍길동".getBytes())); // http://localhost:8080/jspwork/ch05_1/main.jsp?name=yKux5rW/ // main.jsp 님 안녕하세요!// ..
빈 Dictionary 이용: words = "a b c d a c" word_list = words.split()# ['a', 'b', 'c', 'd', 'a', 'c'] dict = {}#빈 딕셔너리 for word in word_list: if word in dict:# 이미 있는 키 dict[word] += 1 else:# 처음 보는 키 dict[word] = 1 for key,value in dict.items(): print("{}: {}개".format(key, value), end=" ")# a: 2개 b: 1개 c: 2개 d: 1개 리스트에서 중복되는 값의 갯수를 알고 싶을 때, 값을 split()로 나눈 후 빈 딕셔너리 생성 이미 있는 경우, 없는 경우로 나눠서 갯수를 세렸다. Coun..
model from django.db import models from django.conf import settings from django.shortcuts import resolve_url from django.utils.text import slugify#라이브러리 class Profile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) nickname = models.CharField(max_length=20) profile_photo = models.ImageField(upload_to="profile/" , blank=True) slug = models.SlugField(..
텍스트 업로드 views.py def create(request): new = Diary() new.title = request.GET['title'] new.body = request.GET['body'] new.pub_time = timezone.datetime.now() new.save() return redirect(new) 클래스 인스턴스 생성 request.GET["html name"]으로 value 가져옴 save메소드로 저장 get_absolute_url을 이용해 디테일 페이지로 이동 이미지 업로드 models.py class Diary(models.Model): title = models.CharField(max_length=20) image = models.ImageField(uploa..