본문 바로가기

DoItDJango21

User Accounts Chapter 8: Custom User Model Django's built-inUser modelallows us to start working with users right away, as we just did with our Blog app in the previous chapters. However theofficial Djangodocumentationhighly recommends using a custom user model for new projects. Thereason is that if you want to make any changes to the User model down the road–-for example adding an age field-–using a cust.. 2023. 4. 16.
Forms 2023. 4. 15.
Blog App 이 장에서는 사용자가 게시물을 만들고, 편집하고, 삭제할 수 있는 블로그 애플리케이션을 빌드합니다. 홈페이지에는 모든 블로그 게시물이 나열되며 각 개별 게시물에 대한 전용 세부 정보 페이지가 있습니다. 또한 스타일링을 위한 CSS를 소개하고 Django가 정적 파일과 함께 작동하는 방법을 배웁니다. 1. project folder > blog App 생성 $ python manage.py startapp blog 2. setting파일에 app 등록 # blog_project/settings.py INSTALLED_APPS = [ .... 'blog.apps.BlogConfig', # blog app등록 ] 3. initial installation 확인 http://127.0.0.1:8000/ 4. D.. 2023. 4. 15.
텍스트 콘텐츠를 저장하는 모델 만들기 게시판 게시물의 텍스트 콘텐츠를 저장하는 모델을 만들려고 하며, 다음과 같이 할 수 있습니다. 강력한 Django ORM (Object-Relational Mapper) 덕분에 PostgreSQL, MySQL, MariaDB, Oracle 또는 SQLite와 같은 여러 데이터베이스 백엔드에 대한 지원이 내장되어 있습니다. 즉, 개발자로서 models.py 파일에 동일한 코드를 작성할 수 있으며 자동으로 각 데이터베이스로 올바르게 변환됩니다. 필요한 유일한 구성은 settings.py 파일의 DATABASES 섹션을 업데이트하는 것입니다. 이것은 정말 인상적인 기능입니다! 1. 프로젝트 root에 posts App생성 python manage.py startapp posts 2. app 등록 # mb_pr.. 2023. 4. 14.
Django Admin 사용 Django Admin Django의 강력한 내장 관리 인터페이스입니다. Django가 원래 신문 CMS(콘텐츠 관리 시스템)로 구축되었기 때문에 생겨났습니다. 저널리스트가 "코드"를 건드릴 필요 없이 관리자에서 기사를 작성하고 편집할 수 있다는 것이었습니다. 1. 관리자를 사용하려면 먼저 로그인할 수 있는 수퍼유저를 생성해야 합니다. 명령줄 콘솔에서 python manage.py createsuperuser를 입력하고 사용자 이름, 이메일 및 암호를 입력 2. 서버 재구동 3. http://127.0.0.1:8000/admin/ 접속 확인 2023. 4. 14.
Heroku 정리 요망 Heroku You can sign up for a free Heroku account on their website. After you confirm your email Heroku will redirect you to the dashboard section of the site. Heroku dashboard Now we need to install Heroku’s Command Line Interface (CLI) so we can deploy from the command line. We want to install Heroku globally so it is available across our entire computer. Open up a new command line tab: C.. 2023. 4. 14.
template 사용 - class기반 뷰어 생성 1. App 아래에 templates 폴더 생성 - 아래에 home.html 파일 생성 Homepage 2. project setting.py의 templates 설정 'DIRS': [os.path.join(BASE_DIR, 'templates')], # templates 경로 추가 3. views.py 수정 from django.views.generic import TemplateView class HomePageView(TemplateView): template_name = 'home.html' 4. urls.py 수정 - Class-Based View 사용 # project_home/urls.py from django.urls import path, include # new urlpatterns =.. 2023. 4. 13.
데이터 저장 이번 장에서는 답변을 등록하는 기능을 만들어 보자. 답변등록 폼 질문 상세 템플릿에 다음처럼 답변을 저장할 수 있는 폼(form)을 추가하자. [파일명: projects\mysite\templates\pybo\question_detail.html] {{ question.subject }} {{ question.content }} {% csrf_token %} 답변의 내용을 입력할 수 있는 텍스트창(textarea)과 답변을 저장 할 수 있는 "답변등록" 버튼을 추가했다. 답변 저장을 위한 URL은 form 태그의 action 속성에 {% url 'pybo:answer_create' question.id %}로 지정했다. form 태그 바로 밑에 보이는 {% csrf_token %}은 보안에 관련된 항목으.. 2023. 4. 13.
URL 별칭 참조 : https://wikidocs.net/70741 2-05 URL 별칭 * `[완성 소스]` : [github.com/pahkey/jump2django/tree/2-05](https://github.com/pahkey/jump2django/tree/… wikidocs.net URL 별칭 이번 장에서는 템플릿에 사용된 URL의 하드코딩을 없애는 방법에 대해서 알아보자. URL 하드코딩 먼저 question_list.html 템플릿에 사용된 다음 링크를 보자. {{ question.subject }} 질문 상세를 위한 URL 링크이다. 하지만 이러한 URL 링크는 수정될 가능성이 있다. 예를 들어 http://localhost:8000/pybo/question/2 또는 http://localhost:.. 2023. 4. 13.