Part 4: 將內容顯示在前端首頁 - amychenmit/misdj002 GitHub Wiki

Create new file ‘urls.py’ under misdj002/note


from django.urls import path
from . import views
app_name = 'note'

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

edit views.py


from django.shortcuts import render

from .models import Note
def index(request):
list = Note.objects.all()
context = {’list’: list}
return render(request, ‘note/index.html’, context)

new file templates/note/index.html

<h1><br>Amy's Note</h1>

{% for x in list %}



{{x.subject}}


{{x.detail|linebreaks}}

{% endfor %}

edit misdj/urls.py
#橘色的字不要動喔~


from django.contrib import admin
from django.urls import path,include #讓NOTE在網頁上顯示

urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘’, include(’note.urls’)), #讓NOTE在網頁上顯示
]

可以查看前端,應該就成功啦~
http://127.0.0.1:8000/

【美化前端網頁顯示】
Get 2 files to your local project, then run your local server.
https://github.com/twoutlook/misdj002/tree/master/note/templates/note

⚠️ **GitHub.com Fallback** ⚠️