后面的TITLE每次刷新都会多一个,是因为自增吗?
见下面的图片
见下面的图片
2018-07-19
修改部分如下:
urls.py:
urlpatterns = [
path('', views.index,name='index'),
path('artile/<int:artile_id>/', views.artile_page,name='artile_page'),
path('edit',views.edit_page,name='edit_page'),
path('edit/action',views.edit_action,name='edit_action'),
]
views.py:
1.加两个头文件:
from django.http import HttpResponse,HttpResponseRedirect
from django.urls import reverse
2.edit_action函数返回值return render()改为return HttpResponseRedirect(reverse('blog:index')),即:
def edit_action(request):
title = request.POST.get('title','Title')
content = request.POST.get('content','Content')
models.Artile.objects.create(title=title,content=content)
return HttpResponseRedirect(reverse('blog:index'))
望采纳
举报