from django import views
from django.shortcuts import render
from django.urls import path
# Create your views here.
"""打开主页"""
def index(request):
return render(request,"index.html")
def addBlog(request):
title = request.POST.get("title")
content = request.POST.get("content","默认内容")
newBlog = Blog(title=title,content = content)
newBlog.save()
return render(request,"index.html")
urlpatterns = [
path('index/',views.index),
path('add/',views.addBlog),
]
def getBlogs():
blogs = Blog.objects,order_by("create_time")
return blogs