0
我正在試圖爲我的輸入文本框添加降價項目。我正在關注格林堡的教科書。在我forms.py我:未捕獲ReferenceError:Markdown沒有定義
from flask_pagedown.fields import PageDownField
from wtforms.fields.simple import HiddenField
class NewEntry(Form):
'''
A form for new entries
'''
title = TextAreaField("Title", validators=[Required()])
text = PageDownField("Text", validators=[Required()])
tags = TextAreaField("Tags", validators=[Required()])
srcLibEntries = HiddenField(label=None, id="srcLibArticles")
submit = SubmitField('Submit', id="new_entry_submit_button")
在我的HTML,我有:
{% extends "layout.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block scripts %}
{{super()}}
{{pagedown.include_pagedown()}}
{% endblock %}
{% block body %}
<form method="post" role="form">
{{ wtf.form_field(form.title) }}
{{ wtf.form_field(form.text) }}
{{ wtf.form_field(form.tags) }}
{{ form.srcLibEntries }}
{{ wtf.form_field(form.submit) }}
</form>
所有這一切都在隨即渡過瀏覽器具有文本輸入框下面的代碼:
<div class="form-group required"><label class="control-label" for="text">Text</label>
<div class="flask-pagedown"><textarea class="form-control flask-pagedown-input" id="flask-pagedown-text" name="text" required>fsdafds</textarea></div>
<div class="flask-pagedown-preview" id="flask-pagedown-text-preview"></div>
<script type="text/javascript">
f = function() {
if (typeof flask_pagedown_converter === "undefined")
flask_pagedown_converter = Markdown.getSanitizingConverter().makeHtml;
var textarea = document.getElementById("flask-pagedown-text");
var preview = document.getElementById("flask-pagedown-text-preview");
textarea.onkeyup = function() { preview.innerHTML = flask_pagedown_converter(textarea.value); }
textarea.onkeyup.call(textarea);
}
if (document.readyState === 'complete')
f();
else if (window.addEventListener)
window.addEventListener("load", f, false);
else if (window.attachEvent)
window.attachEvent("onload", f);
else
f();
</script>
</div>
我收到瀏覽器的異常,即「Uncaught ReferenceError:Markdown is not defined」,它指的是這條線:
flask_pagedown_converter = Markdown.getSanitizingConverter().makeHtml;
我不認爲我必須導入任何更多 markdown任何地方。這裏發生了什麼?
編輯1:
我需要添加以下到我的layout.css中:
<script src="//cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.js"> </script>
<script src="//cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Editor.js"> </script>
<script src="//cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.js"> </script>
是什麼讓你認爲你不必導入降價腳本? –
這只是不在任何地方的教科書或示例代碼。我想我需要進口。你能幫我嗎?此外,還有一個從文本中包含的降價導入(請參閱代碼)。這不是我需要的一切嗎? – user442920
看看http://stackoverflow.com/questions/13013315/how-to-use-pagedown-markdown-editor – jsfan