李老师我在配置的时候出现这个问题:
代码截图:
# views.py
@main.route('/new',methods=['GET', 'POST'])
def new():
"""View function for new_port."""
form = PostForm()
if form.validate_on_submit():
#new_post = Post(title=form.title.data)
#title = form.title.data
#new_post.body = form.body.data
# new_post.publish_date = datetime.now()
#db.session.add(new_post)
#db.session.commit()
flash('提交成功','success')
#return redirect(url_for('.lists'))
return render_template('xxy/post.html',form=form)
@main.route('/files/<filename>')
def uploaded_files(filename):
path = current_app.config['UPLOAD_FOLDER']
return send_from_directory(path, filename)
@main.route('/upload', methods=['POST'])
def upload_images():
path = current_app.config['UPLOAD_FOLDER']
f = request.files.get('upload') # 获取上传图片文件对象
# Add more validations here
if extension not in ['jpg', 'gif', 'png', 'jpeg']: # 验证文件类型示例
return upload_fail(message='Image only!') # 返回upload_fail调用
f.save(os.path.join(path, f.filename))
url = url_for('uploaded_files', filename=f.filename)
return upload_success(url=url) # 返回upload_success调用
# config.py
CKEDITOR_SERVE_LOCAL = True
CKEDITOR_PKG_TYPE = 'standard'
CKEDITOR_LANGUAGE = 'zh-CN'
CKEDITOR_HEIGHT = 600
CKEDITOR_WIDTH = 300
CKEDITOR_FILE_UPLOADER = 'upload_images'
CKEDITOR_ENABLE_CSRF = True
UPLOAD_FOLDER = os.path.join(basedir, 'uploads')
ALLOWED_EXTENSIONS = {'png', 'jpg', 'gif', 'jpeg'}
MAX_CONETNT_LENGTH = 16 * 1024 * 1024
# post.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flask-CKEditor Demo</title>
</head>
<body>
<div class="warpper" style="width: 700px; margin: auto">
<h1>Flask-CKEditor Demo: Image Upload</h1>
<form method="post" ">
{{ form.csrf_token }}
{{ form.title.label }}<br>
{{ form.title }}<br><br>
{{ form.body.label }}<br>
{{ form.body }}
<br>
{{ form.submit(class="btn btn-primary") }}
</form>
</div>
{{ ckeditor.load() }}
{{ ckeditor.config(name='body') }}
</script>
</body>
</html>
我这边使用的是蓝图 ,分了auth,跟main两个蓝图。主要的函数都写在main这里面的。
报错如下,烦请问下是哪里出问题了,谢谢。