- 建立簡單頁面
- 建立app(一個app就是一個功能):
./manage.py startapp helloworld
- myblog/settings.py
INSTALLED_APPS = [
...
'helloworld',
]
- 建立 function view
helloworld/views.py
:
from django.http import HttpResponse
def greeting(request): #function view
return HttpResponse('hello world')
from django.contrib import admin
from django.urls import path
from helloworld import greeting #匯入用
urlpatterns = [
path('admin/', admin.site.urls),
path(r'index/', greeting), # 追加
]
- 移除 app:
- urls.py 移除 function
- setting.py 移除 app
- 移除 app 的資料夾