9、續7--文章的編寫頁面(略)
- views.py修改如下:
def edit_page(request,article_id):n if str(article_id)==0:n return render(request,"blog/edit_article.html")n article=models.Article.objects.get(pk=article_id)n return render(request, "blog/edit_article.html", {article: article})nnndef action_page(request):n title=request.POST.get("title")n content=request.POST.get("content")n article_id=request.POST.get("article_id",0)n if article_id==0:n models.Article.objects.create(title=title,content=content)n articles = models.Article.objects.all()n return render(request, "blog/index.html",{articles:articles})n article=models.Article.objects.get(pk=article_id)n article.title=titlen article.content=contentn article.save()n return render(request,"blog/article_page.html",{article:article})n
- urls.py修改如下
urlpatterns = [n url(r^admin/, admin.site.urls),n url(r^current_time/(d{1,2})/$,current_time),n url(r^blog1/,include("blog.urls",namespace="blog")),n url(r^blog2/,include("blog2.urls")),nn]n
推薦閱讀:
※為什麼python中不建議在for循環中修改列表?
※Python技術分享的亂象
※Python 黑帽編程大綱(變化中)
※Python爬蟲實戰六之抓取愛問知識人問題並保存至資料庫
TAG:Python |