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')
# title = request.POST['title']
# content = request.POST['content']
models.Article.objects.create(title=title,content=content)
# return HttpResponseRedirect(reversed('/blog/index/'))
articles = models.Article.objects.all()
return render(request, 'blog/index.html', {'articles': articles})
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Edit Page</title>
</head>
<body>
<form action="/blog/edit/action/" method="post">
{% csrf_token %}
<label>Title
<input type="text" name="Title">
</label>
<br/>
<label>Content
<input type="text" name="Content">
</label>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
urlpatterns = [
re_path('index/', views.index),
re_path('article/(?P<article_id>[0-9]+)/', views.article_page,name = 'article_page'),
# re_path('article/(?P<article_id>[0-9]+)/', views.article_page),
re_path('edit/',views.edit_page,name = 'edit_page'),
re_path('edit/action/',views.edit_action, name = 'edit_action'),
]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{#<h1>{{ article.title }}</h1>#}
{#<h3>{{ article.content }}</h3>#}
<h1>
<a href="">新文章</a>
</h1>
{% for article in articles %}
<a href="{%url 'blog:article_page' article.id %}">{{ article.title }}</a>
{# <a href="/blog/article/{{ article.id }}">{{ article.title }}</a>#}
<br/>
{% endfor %}
</body>
</html>
