티스토리 뷰

공부합시다/python

Django RESTframework

IamMH 2020. 6. 25. 09:36
  1. 환경설정
    1.1. 기본구성

    • pip >= 19.0.3

    • python >= 3.4 (django 2.2 지원 최소버전)

      # pip upgrade last version
      pip install --upgrade pip
      
      # check pip version
      pip --version
      pip 19.0.3 from /Users/.../pip-19.0.3-py3.7.egg/pip (python 3.7)

    1.2. install django

     pip install django==2.2
     pip install djangorestframework==3.11.0
    
     $ django-admin startprject {project_name}
    
     $ ls
     {project_name}/
    
     # django server start
     $ .manage.py runserver 

    1.3. create app
    1개 프로젝트에 1개이상의 앱을 구성할 수 있다.

     예시: 호스팅 프로젝트에 여러개 앱 구성
     ex) hosting (project)
         ㅣ- hosting (app)   
         ㅣ- webhosting(app)       
         ㅣ- dbhosting(app)   
         ㅣ- ...
     
     $ .manage.py startapp {app_name}
     $ ls
     db.sqlite3  manage.py*  {app_name}/  {project_name}/
    
     $ .manage.py migrate
     (...)
     Applying sessions.0001_initial... OK 

    1.4. create super user

     $ .manage.py createsuperuser
     Username (leave blank to use 'admin'): 
     Email address: {email}
     Password: 
     Password (again): 
     Superuser created successfully.
    
댓글