전체보기
-
[django] shell을 더 편하게 쓰는 법, 장고 ORM을 shell 외에서 사용Python/초간단 장고 Django 2022. 9. 12. 10:27
장고 쉘을 더 편하게 쓰는 법.. 1. ipython을 설치한다. 파이썬 유저라면 다들 노트북을 써보셨을 겁니다. IDE만큼 편하진 않지만.. 맨땅의 헤딩보다는 엄청 편리하죠... 2. 장고 ORM을 shell 외에서 사용 개발 환경 설정에 따라 다르겠습니다만 manage.py 가 있는 디렉토리에서 스크립트를 작성, 실행하는 것이 편할 겁니다. 개별 앱에 관련된 코드를 루트에 두는 게 불편합니다만... 장고 셋업을 한 뒤에야 모델을 import 할 수 있습니다. DB 초기화를 할 때, preset 데이터를 입력할 때, 사용하면 편합니다. import csv import os import django os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.set..
-
[django] RedirectView, redirect in urls.pyPython/초간단 장고 Django 2022. 9. 9. 00:42
board.urls을 2번 인클루드하면 경고가 발생합니다. from django.contrib import admin from django.urls import path, include urlpatterns = [ path('', include('board.urls')), path('board/', include('board.urls')), path('admin/', admin.site.urls), ] WARNINGS: ?: (urls.W005) URL namespace 'board' isn't unique. You may not be able to reverse all URLs in this namespace 이 상황에서 redirect를 만나면 라우팅이 엉망이 되죠. 그땐 경고가 아닌 에러가 발생합니..
-
django as.view() 그리고 dispatch()Python/초간단 장고 Django 2022. 9. 7. 23:59
https://docs.djangoproject.com/en/4.1/ref/class-based-views/base/ Base views | Django documentation | Django Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate docs.djangoproject.com 클래스 뷰의 작동은 위 링크에 잘 설명되어 있습니다. urls.py에 등록된 view class는 아래와 같이 작동합니다. response = MyView.as_view()(request) as.view()가 진입점이 되죠. 진입 후에는..
-
django {% with %}Python/초간단 장고 Django 2022. 9. 7. 23:17
https://docs.djangoproject.com/en/4.1/ref/templates/builtins/#with Built-in template tags and filters | Django documentation | Django Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate docs.djangoproject.com Caches a complex variable under a simpler name. 복잡한 변수를 더 간단한 이름으로 캐시합니다. This is useful when accessing an ..
-
566. Reshape the Matrix코딩 테스트/Level 1 2022. 9. 7. 17:36
https://leetcode.com/problems/reshape-the-matrix/ Reshape the Matrix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com from typing import List class Solution: def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: flat = tuple(each for row in mat for each..
-
-
선입 선출 스케줄링코딩 테스트/Level 3 2022. 9. 4. 10:29
https://school.programmers.co.kr/learn/courses/30/lessons/12920 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 파이썬 무지성 코딩. def solution(n, cores): board = [0 for _ in cores] while True: for i, v in enumerate(cores): if board[i] == 0: n -= 1 board[i] = v if n == 0: return i + 1 for i in range(len(cores)): board[i] -= 1 이분(이진) 탐색 파라메트..
-
[파이썬] count, Counter with dictionaryPython/이것저것 파이썬 2022. 8. 30. 07:31
list.count() # list.count() 메서드를 이용. some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n'] duplicates = set() for each in set(some_list): if some_list.count(each) > 1: duplicates.add(each) print(duplicates) # 컴프리헨션으로 정리 duplicates = set(each for each in set(some_list) if some_list.count(each) > 1) print(duplicates) dictionary # 딕셔너리를 이용. some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n'] counte..