【djnago】create API project

install 

install python3
pip install django pip install djangorestframework pip install django-filter

create

django-admin startproject (project)
cd (project)
django-admin startapp (app)

cd (app)

create urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url('', views.index, name='index'),
]

 

views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse('<h1>Hello, myapp1!</h1>')

 

cd (project)

modify urls.py

from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include

urlpatterns = [

path('admin/', admin.site.urls),
url('api/', include('api.urls')),
]
INSTALLED_APPS = [

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
]

 

python manage.py makemigrations
python manage.py migrate

 

(app)/adimn.py

from django.contrib import admin

# Register your models here.
from .models import Staff
from .models import TimeCard
from .models import Record
admin.site.register(Staff)
admin.site.register(TimeCard)
admin.site.register(Record)

 

Leave a Reply