본문 바로가기
반응형

WEB/Python-Django29

Django 404에러 메시지 출력 from django.http import Http404from django.shortcuts import renderfrom .models import Question# ...def detail(request, question_id): try: question = Question.objects.get(pk=question_id) except Question.DoesNotExist: raise Http404("Question does not exist") return render(request, 'polls/detail.html', {'question': question})이게 일반적인 404 에러 메시지 출력 코드그리고 아래가 숏컷 코드이다.from django.. 2025. 6. 10.
알아두면 좋은 Ubuntu 명령어 cd 경로 : 원하는 경로로 ㄱㄱ( 어느 정도 입력 후, tab키 누르면 나머지 폴더명 자동 생성 )cd .. : 한 단계 이전 경로로 이동( * cd 띄어쓰기 ..)touch 새 파일 경로 : 새 파일 생성unzip 파일명.zip : zip파일 압축 풀기tar -zxvf [파일명.tar.gz] : tar.gz파일 압축 풀ls : 경로 안에 있는 폴더 및 파일들 봄ls -A : 경로 안에 있는 숨긴 폴더 및 파일들도 봄* 폴더 내에서 숨긴 파일 보기 : ctrl + H 2025. 6. 10.
Django 이미지 1. App폴더 안에 templates 폴더 생성2. templates폴더 안에 App폴더와 같은 이름의 폴더 생성3. 생성한 templates/App폴더 안에 index.html 파일 생성touch 경로/index.html4. 보여질 화면을 만든다.index.html{% if latest_question_list %} {% for question in latest_question_list %} {{ question.question_text }} {% endfor %} {% else %} No polls are available.{% endif %}5. index클래스에 방금전에 index.html로 만든 화면을 불러오는 코드를 작성한다.polls/views.py.. 2025. 6. 10.
Django 어드민 1. 어드민 유저 만들기python manage.py createsuperuser 2. 서버를 실행시키 후, 주소 뒤에 /admin/을 추가하면 아래와 같은 어드민 화면이 보여진다.3. Question 오브젝트를 어드민 사이트에서 사용하려면 어드민 앱에게 Question 오브젝트가 어드민 인터페이스를 가지고 있다고 얘기해 줘야 합니다. polls/admin.pyfrom django.contrib import adminfrom .models import Questionadmin.site.register(Question) 4. 다시 어드민 주소로 들어가면 다음과 같이 POLLS 폴더가 보여진다. 2025. 6. 7.
반응형