Django模板中的過濾器報錯:django.template.exceptions.TemplateSyntaxError: default_if_none requires 2 arguments
今天在進行遇到一個Django開發時遇到一個問題,過濾器一直報錯:
django.template.exceptions.TemplateSyntaxError: default_if_none requires 2 arguments, 1 provided
一直提示我過濾器缺少引數,上程式碼:
<body> 使用者名稱: {{ name|default_if_none: "遊客" }} </body>
上面的程式碼如此簡單,乍一看,沒毛病吧!!!
可以是它就是報錯!!!
我之前寫登入的時候什麼問題都沒有,今天再來寫就一直報錯,我以為是我用發不對,於是我查了一堆資料,文件,愣是沒找到錯誤!
最後我刪除了過濾器和值中間的空格,可以了... ...就是因為中間有個空格... ...
寫python程式碼都習慣性的在寫完關鍵字或者冒號後面按個空格,沒想到在這還就真不能有空格
相關推薦
Django模板中的過濾器報錯:django.template.exceptions.TemplateSyntaxError: default_if_none requires 2 arguments
今天在進行遇到一個Django開發時遇到一個問題,過濾器一直報錯: django.template.exceptions.TemplateSyntaxError: default_if_none requires 2 arguments, 1 provided 一直提示我過濾器
Django查詢models物件報錯:TypeError: __str__ returned non-string (type decimal.Decimal)
執行環境: python 3.6.1Django 1.11.3 modles.py 添加了如下的物件: class ApplStockPrice(models.Model): Date =
建立django專案報錯:Django not found
下載Django安裝之後,在eclipse中新建一個Django工程,點選下一步時,發現報錯: 根據提示資訊進行查詢,發現是Django沒有匯入eclipse,Python是早就安裝在eclips
Springboot中mybatis報錯:Invalid bound statement (not found)
小場面不要驚慌,分5種情況,檢查你的配置和程式碼,看有沒有中招; xml檔案的select標籤的id對應dao檔案的方法名,兩者必須完全一致 xml檔案中的 namespace=“xxx.xxx.xxx.Mapper” 中的路徑是否與介面檔案路徑一致 xml檔案中的p
python中json報錯:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)
一、json.loads(json_data) 報錯json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19) 原因:json預設使用的是嚴謹格式,當跨語言傳遞資料時,就容易報
如何解決在使用VScode編輯器vue開發過程中出現報錯:Elements in iteration expect to have ‘v-bind:key’ directives
報錯資訊如下:[eslint-plugin-vue][vue/require-v-for-key] Elements in iteration expect to have 'v-bind:key' directives.這是因為我們安裝了ESLint外掛,對vue進行了es
cmd命令列中java報錯:找不到或無法載入主類 HelloWorld
1.cmd命令列java報錯: 2.解析: 關於變數: JAVA_HOME: 配置“JDK”安裝目錄。(例如:C:\Program Files (x86)\Java\jdk1.7.0)
vue報錯:Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.
顯示 sin ont img root png ima pan 如果 在.vue文件中引入了 element-ui 的 table 和 pagination 組件後,報錯:Component template should contain exactly one root
爬蟲學習-selenium配合ChromeDriver報錯:selenium.common.exceptions.WebDriverException: Message: 'chromedriver'
selenium配合ChromeDriver報錯:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH; 程式碼如下: from sele
報錯:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
C:\Users\哀鳴嘯天>chromedriver Starting ChromeDriver 2.28.455520 (cc17746adff54984afff480136733114c6b3704b) on port 9515 Only local connections are a
WebStorm執行Node.js檔案報錯:runnerw.exe: CreateProcess failed with error 2
點選工具欄的 Run —> Edit Configurations… 可以看到我這裡是 Node interpreter 的路徑錯了 選擇一個正確的路徑即可 注意:也有可能是另一
maven項目中的報錯問題——Dynamic Web Module 3.0 requires Java 1.6 or newer.
project 情況下 web3.0 copy java版本 目錄 web 安裝 pre 當創建動態的web 3.0的項目時需要java1.6及以上的版本支持; 而我們的eclipse中創建的maven骨架默認是java1.5的版本,這種情況下就會報以下的錯誤:Dynami
django模板中的自定義過濾器
tag span .lib 名稱 models mod ppa har import (1)在APP下創建templatetags文件夾,與Models.py、views.py等同級,templatetags文件夾下添加__init__.py文件,可為空,再添加一個模塊文件
python3 與 Django 連接數據庫報錯:ImportError: No module named 'MySQLdb'
port sta 數據庫 init code mysqld error 連接數 imp 在 python2 中,使用 pip install mysql-python 進行安裝連接MySQL的庫,使用時 import MySQLdb 進行使用 在 python3 中,改變了
Django 使用form表單提交數據報錯: Forbidden (403)
運行 ges info auth 技術 sage ons 提交數據 smi Issue: 使用from表單submit之後報錯入下: Action: 把django工程文件的setting.py中的django.middleware.csrf.CsrfViewMi
Django報錯:” File “manage.py”, line 14 ) from exc ^ SyntaxError: invalid syntax”
Django 1.7.1及以上 用以下命令 # 1. 建立更改的檔案 python manage.py makemigrations # 2. 將生成的py檔案應用到資料庫 python&
【Python】django報錯:TypeError: __init__() missing 1 required positional argument: 'on_delete'解決辦法
錯誤程式碼: from __future__ import unicode_literals from django.db import models from django.utils.encoding import python_2_unicode_compatible
Django需求分析和model設計過程中系列報錯解決方法
報錯一:django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_init 進入執行介面後,執行遷移時報錯: django.db.migrations.exce
Python3環境下django連線mysql報錯:No module named 'MySQLdb'
原因是python3中使用了一個新的模組,叫做pymysql,可以直接pip安裝 pip安裝完成後,在django專案的manage.py檔案中新增下面兩行就OK了: from django.cor
Django報錯:TypeError: render() got an unexpected keyword argument 'renderer'
這是由於整合DjangoUeditor時出錯: 需要修改虛擬環境下的:boundfield.py檔案: .virtualenvs/虛擬環境檔案/lib/python3.5/site-packages/django/forms/boundfield.py 89 return wi