为什么我现实的结果是TiTLE和CONTENT
edit_page.html
<form action="{% url 'blog:edit_action' %}",method ="post"> {% csrf_token %} <label for="">文章标题 <input type="text" name="title" value="{{ article.title }}"> </label> <br> <label for="">文章内容 <input type="text" name="content" value="{{ article.content }}"> </label> <br> <input type="submit" value="提交"> </form>
urls.py
from django.urls import path,re_path from django.conf.urls import url from . import views #import blog.views as bv app_name = 'blog' urlpatterns = [ re_path('^$', views.index), path('article/<int:article_id>/',views.article_page,name='article_page'), re_path('^edit/$',views.edit_page,name='edit_page'), re_path('^edit/action/$',views.edit_action, name='edit_action'), ]
views.py
from django.http import HttpResponse from . import models # Create your views here. def index(request): #return render(request,'index.html',{'hello blog4!':'hello'}) articles = models.Article.objects.all() return render(request, 'blog/index.html', {'articles':articles}) def article_page(request,article_id): article = models.Article.objects.get(pk=article_id) return render(request, 'blog/article_page.html', {'article':article}) def edit_page(request): return render(request,'blog/edit_page.html') def edit_action(request): title = request.POST.get('title', 'TITLE') content = request.POST.get('content', 'CONTENT') models.Article.objects.create(title=title, content=content) articles = models.Article.objects.all() return render(request, 'blog/index.html', {'articles': articles})