OS:MacOS X node:v12.14.1 npm:6.13.4 @vue/cli:4.1.2 python:3.7.4 Django:2.2.6 django-rest-framework:0.1.0
See here to be able to do the following: ・ Pyenv can be used -You can create a Python virtual environment with pyenv-virtualenv
Create a virtual environment for python 3.7.4. The name is "concentratio" because it causes nervous breakdown.
butterthon$ pyenv virtualenv 3.7.4 concentratio
That's all for creating a virtual environment.
Create a project root directory and apply the virtual environment.
butterthon$ mkdir workspace #Prepare a workspace
butterthon$ cd workspace
workspace$ mkdir concentratio #Create application root directory in workspace (name is arbitrary)
workspace$ cd concentratio
concentratio $ pyenv local concentratio
(concentratio)concentratio$ python -V
Python 3.7.4
concentratio$ django-admin startproject config .
It has the following configuration.
concentratio #Project root directory
├── config #Configuration files are organized under config
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
Start the Django server with ` python3 manage.py runserver ` and access [http: // localhost: 8000](http: // localhost: 8000).
(concentratio)concentratio$ python3 manage.py runserver #Start Django server
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 08, 2020 - 15:35:47
Django version 2.2.6, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
It's OK if the screen where the rocket is launching is displayed! !! !!
(concentratio)concentratio$ pip install django-rest-framework
After installation, add it to the configuration file.
config/settings.py
.
..
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework', #add to
]
...
..
.
List API endpoints
config/urls.py
.
..
...
from django.contrib import admin
from django.urls import path
from django.conf.urls import include, url #add to
from rest_framework import routers #add to
ROUTER = routers.DefaultRouter() #add to
urlpatterns = [
path('admin/', admin.site.urls),
url('api/', include(ROUTER.urls)), #add to
]
Check if the Django Rest Framework can be started correctly by accessing [http: // localhost: 8000 / api](http: // localhost: 8000 / api)
Recommended Posts