본문 바로가기

반응형

Django

(37)
Visual Studio Code에서 Django Debug Mode 1. Project 아래에 .vscode를 만들고 launch.json을 생성한다. 2. configurations에 아래 옵션을 추가한다. "pythonPath": "%Absolute Path%/django/env/bin/python", 3. Debugging 한다. 26Line에 Breakpoint 걸려있는 모습. 대표사진 삭제 사진 설명을 입력하세요.
django db admin 계정 사용하기. create user 1. db 계정 생성 $ python manage.py createsuperuser Username (leave blank to use '###'): {account} Email address: ###### Password: Password (again): Bypass password validation and create user anyway? [y/N]: y Superuser created successfully. 2 admin.py 파일에 생성한 Post 모델을 추가하여 관리가 되도록 하자. from django.contrib import admin from .models import Post # Register your models here. admin.site.register(Post) 3. a..
Python Shell 이용하여 명령어 실행시키기 1. shell로 들어가자 $ python manage.py shell Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) 2. model을 가져와서 지금 들어 있는 Query set이 얼마나 있는지 확인하자 >>> from HelloWorld.models import Post >>> Post.objects.all() 3. 저장된 Query가 없으니 하나 넣어서 잘 들어갔는지 확인해 보자 >>> post = Post(post_..
Django Model 생성하기 https://docs.djangoproject.com/en/4.0/intro/tutorial02/ 이미지 썸네일 삭제 Writing your first Django app, part 2 | Django documentation | Django Writing your first Django app, part 2 ¶ This tutorial begins where Tutorial 1 left off. We’ll set up the database, create your first model, and get a quick introduction to Django’s automatically-generated admin site. Where to get help: If you’re having trouble ..
Django sqlite3 기초 https://docs.djangoproject.com/en/4.0/intro/tutorial02/ 이미지 썸네일 삭제 Writing your first Django app, part 2 | Django documentation | Django Writing your first Django app, part 2 ¶ This tutorial begins where Tutorial 1 left off. We’ll set up the database, create your first model, and get a quick introduction to Django’s automatically-generated admin site. Where to get help: If you’re having trouble ..
Django에서 Static File 읽어오기 1. Settings.py에 아래 설정을 추가한다. STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join('static'), ) 2. Static 파일을 읽어들이기 위해 html 상단에 아래 코드를 넣는다. {% load static %} 흰 배경흰 배경회색 가로줄 배경회색 가로줄 배경어두운 배경어두운 배경 삭제삭제 3. 사용되는 template html에서 사용하고자 하는 static file은 아래와 같이 지정한다. {% static '' %} 예시
Shell을 이용하여 가상환경 바로 들어가기 가상 환경을 매번 디렉토리 위치 바꿔가며 실행하지 않는 방법 1. 기본 project 폴더에 goenv.sh을 하나 만든다. #! /bin/bash source "/env/bin/activate" 2. 파일이 생성 된 이후에는 아래 명령어만 입력하면 바로 가상 환경에 진입한다. source goenv.sh 3. 서버 구동도 shell로 만들어서 하자. #! /bin/bash python manage.py runserver
Django Template을 이용한 html 호출 1. django.template의 loader를 이용하는 방법 from django.http import HttpResponse from django.template import loader def index(request): template = loader.get_template('HelloWorld/index.html') context = {} return HttpResponse(template.render(context, request)) 2. shortcuts의 render를 이용하는 방법 from django.http import HttpResponse from django.shortcuts import render def index(request): return render(request, ..

반응형