django前端引數傳輸方式彙總
阿新 • • 發佈:2019-02-08
1,url路徑傳傳參
html程式碼:<a href="{{ blog.id }}">
url程式碼:url(r'^blog/',include('blog.urls',namespace='blog'))
url(r'(?P<article_id>\d)/$',views.blog_article,name='blog_detail') url(r'^article-detail/(?P<id>\d+)/(?P<slug>[-\w]+)/$', views.article_detail, name='article_detail'), 傳輸文字
後端程式碼:def blog_article(request,article_id):
# article = BlogArticle.objects.get(id=article_id)
article = get_object_or_404(BlogArticle,id=article_id)
pub = article.publish
return render(request,'blog/content.html',{'article':article,"publish":pub})