Django csrf 兩種方法設(shè)置form的實(shí)例
第一種方法,在視圖函數(shù)上邊添加一條語(yǔ)句
@csrf_exempt
例子:
@csrf_exempt def login(request): return render_to_response('app/login.html', locals())
上邊的方法是取消csrf的防御機(jī)制。
第二種方法,給出例子,主要為在html的form里面加入{% csrf_token %}這句話,視圖函數(shù)內(nèi)加入render(request, 'app/breakdown_view.html', locals())
例子:
<div class="container"> <form class="form-signin" method="POST"> {% csrf_token %} <h2 class="form-signin-heading">Please login in</h2> <label for="inputEmail" class="sr-only">Email address</label> <input name="loginEmail" type="email" id="inputEmail" class="form-control" placeholder="Email address" value = "{{myLogin.loginEmail}}" required autofocus> <label for="inputPassword" class="sr-only">Password</label> <input name="loginPassword" type="password" id="inputPassword" class="form-control" placeholder="Password" required> <!-- <div class="checkbox"> <label> <input type="checkbox" value="remember-me"> Remember me </label> </div> --> <button class="btn btn-lg btn-primary btn-block" type="submit">Login in</button> </form> </div> <!-- /container -->
def login(request): return render(request, 'app/login.html', locals())
以上這篇Django csrf 兩種方法設(shè)置form的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用Python自制數(shù)據(jù)庫(kù)備份工具實(shí)現(xiàn)數(shù)據(jù)定時(shí)覆蓋
這篇文章主要為大家詳細(xì)介紹了如何使用Python自制數(shù)據(jù)庫(kù)備份工具實(shí)現(xiàn)數(shù)據(jù)定時(shí)覆蓋功能,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考下2024-03-03在Python中實(shí)現(xiàn)貪婪排名算法的教程
這篇文章主要介紹了在Python中實(shí)現(xiàn)貪婪排名算法的教程,也是對(duì)學(xué)習(xí)算法的一個(gè)很好的演示,需要的朋友可以參考下2015-04-04詳解python列表(list)的使用技巧及高級(jí)操作
這篇文章主要介紹了詳解python列表(list)的使用技巧及高級(jí)操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08解決pycharm運(yùn)行時(shí)interpreter為空的問(wèn)題
今天小編就為大家分享一篇解決pycharm運(yùn)行時(shí)interpreter為空的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10pycharm遠(yuǎn)程連接服務(wù)器并配置python interpreter的方法
這篇文章主要介紹了pycharm遠(yuǎn)程連接服務(wù)器并配置python interpreter的方法,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12Python中的HTTP請(qǐng)求庫(kù)Requests的具體使用
Python作為一種功能強(qiáng)大且易于學(xué)習(xí)的編程語(yǔ)言,提供了許多用于處理HTTP請(qǐng)求的庫(kù),其中,Requests庫(kù)是最受歡迎的選擇之一,本文主要介紹了Python中的HTTP請(qǐng)求庫(kù)Requests的具體使用,感興趣的可以了解一下2023-12-12