python—93 自訂的admin後台管理架構 組件filter、pop、open用法

來源:互聯網
上載者:User

標籤:idt   col   cti   cts   頁面   java   關閉   dmi   pytho   

遺忘知識點:

ORM建立記錄的時候book可以被當做返回對象來調用book = Book.object.create(title=title)

 

 

 

一: open

用來實現點擊添加書籍按鈕彈出一個form表單的視窗頁面,需要實現的效果是點擊

提交按鈕時把資料存到資料庫,在把當前提交的書籍渲染到指定位置,並且關閉當前視窗;

<ul>    {% for book in book_list %}        <li>{{ book.title }}</li>    {% endfor %}</ul><hr><a href="javascript:void(0)" onclick="foo(‘con1‘)">點擊1</a><p>con1:</p><p id="con1"></p><a href="javascript:void(0)" onclick="foo(‘con2‘)">點擊2</a><p>con2:</p><p id="con2"></p><script>    function foo(id){        window.open("/addbook/?pop_id=" + id, "", "height=400,width=600,top=300,left=300");    }    function bar(arg, id){        var ele = document.getElementById(id);        ele.innerHTML = arg    }</script>
View Code
<h1>書籍添加</h1><form action="" method="post">    {% csrf_token%}    <p>書籍名稱 <input type="text" name="title"></p>    <input type="submit"></form>
View Code
<h1>POP</h1><script>    window.opener.bar("{{ title }}", "{{ pop_id }}");    window.close()</script>
View Code
def index(request):    book_list = models.Book.objects.all()    return render(request, ‘index.html‘, locals())def addbook(request):    if request.method == ‘GET‘:        return render(request, ‘addbook.html‘)    else:        pop_id = request.GET.get(‘pop_id‘)        title = request.POST.get(‘title‘)        models.Book.objects.create(title=title)        return render(request, ‘pop.html‘, locals())
View Code

 

二:POP

 

 

三:filter

 

python—93 自訂的admin後台管理架構 組件filter、pop、open用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.