본문 바로가기

Python

(52)
[Django template] template 확장하기 / base.html 분리를 통해 html 재사용성 향상 https://github.com/JisunParkRea/my_djangotube JisunParkRea/my_djangotube Simple video service which can upload youtube videos using django - JisunParkRea/my_djangotube github.com DjangoTube 프로젝트를 하나하나 고치면서 프론트로는 기본적인 html과 bootstrap으로만 계속 더해나가다 보니깐, python코드보다 html 코드양이 많아졌다ㅠㅠ 그래서 github에 프로젝트의 대표 언어가 html이 된 것이 맘에 안들어서(지금은 도로아미타불..) 하게 된 django template 정리! base.html DjangoTube 홈화면(VIdeo List)의..
[Django] form을 활용하여 login view 수정하기 기존의 views.py def signin(request): if request.method == 'POST': form = LoginForm(request.POST) username = request.POST['username'] password = request.POST['password'] user = authenticate(username = username, password = password) if user is not None: login(request, user) return redirect('video_list') else: return HttpResponse('Login failed. Try again.') else: form = LoginForm() return render(reque..
[Django] Secret key 새로 생성 후 분리하기 Django Secret key란? [참고] Cryptographic Signing을 제공하는데 사용된다. Cryptographic Signing이란? Web application security의 Golden rule은 신뢰할 수 없는 출처로부터 온 데이터를 절대 신뢰해서는 안된다는 것 하지만 때로는 신뢰할 수 없는 매체를 통해 데이터를 전달하는 것이 유용할 수도 있다. 그렇기에 value를 Cryptographically sign(암호화적으로 서명)하는 것이 필요하다. Secret key 새로 생성 Django Secret Key Generator Secret key 분리 secrets.json { "SECRET_KEY": "여기에 secret key 넣기" } settings.py import js..
[Django DateTimeField] auto_now와 auto_now_add 출처 https://www.geeksforgeeks.org/datetimefield-django-models/ auto_now 갱신될 때마다 시간이 변함 Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps auto_now_add 처음 만들었을 때 시간으로 고정 Automatically set the field to now when the object is first created. Useful for creation of timestamps.
[Django] Hardcoded URL 제거 / Namespacing URL names 출처 Django Documentation -Removing hardcoded URLs in templates Removing hardcoded URLs in templates Hardcoded URLs 예시 {{ question.question_text }} Hardcoded URLs 제거 {% url %} template tag {{ question.question_text }} polls.urls 모듈 # ... path('/', views.detail, name='detail'), Namespacing URL names polls 앱 외에 여러 앱들이 있는 경우 app_name을 명시해줌으로써 url name의 중복을 방지할 수 있다. polls/urls.py from django.urls imp..
[Django ORM] Django QuerySet으로 간단한 검색 기능 구현하기 참고 Django Documentation | QuerySet API reference Django Documentation | Making queries Django Documentation | Search Stackoverflow - Default value of request.GET.get() 초보몽키의 개발공부로그- Queryset을 활용한 아주 간단한 필터검색 구현 실습 저장소 https://github.com/JisunParkRea/djangotube_tutorial JisunParkRea/djangotube_tutorial Simple video service which can upload youtube videos using django - JisunParkRea/djangotube_tut..
[Error solved][Django+Ajax] method object is not JSON serializable 에러 에러 내용 C:\Users\jisun\dev\python\django\djangogirls_video\video\views.py changed, reloading. Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). April 22, 2020 - 19:55:04 Django version 3.0.5, using settings 'djangotube.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [22/Apr/2020 1..
[Django+Ajax/jQuery] '좋아요(likes)' 기능 구현하기 / 전체 웹페이지 새로고침 없이 좋아요 개수 업데이트하기 참고 초보몽키의 개발공부로그 Many-to-many relationships stackoverflow: My own likes button 실습 저장소 https://github.com/JisunParkRea/djangotube_tutorial JisunParkRea/djangotube_tutorial Simple video service which can upload youtube videos using django - JisunParkRea/djangotube_tutorial github.com 구현하고자 하는 기능 마음에 드는 video에 '좋아요'를 누를 수 있게 하기 ajax를 사용하여 웹페이지 새로고침 없이 좋아요 개수를 비동기적으로 업데이트하기 models.py Video는 여러 user로부..