当我运行服务器时,会显示
找不到页面(404)
Django使用notes.urls中定义的URLconf,按以下顺序尝试了这些URL模式:
admin / notes /空路径与任何这些都不匹配
注意urls.py
from django.contrib import admin
from django.urls import include , path
urlpatterns = [
path('admin/',admin.site.urls),
path('notes/', include('notes_app.urls'))
]
notes_app urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$' , views.all_notes , name='all_notes'),
url(r'^(?P<id>[\d]+)$', views.detail , name='note_detail')
]
视图
from django.shortcuts import render
from django.http import HttpResponse
from .models import Note
# Create your views here.
## show all notes
def all_notes(request):
# return HttpResponse('<h1> Welcome in Django Abdulrahman </h1>' , {})
all_notes = Note.objects.all()
context = {
'all_notes' : all_notes
}
return HttpResponse (request , 'all_notes.html' , context)
## show one note
def detail(request , id):
note - Note.objects.get(id=id)
context = {
'note' : Note
}
[enter image description here][1] return render(request,'note_detail.html' , context)