先补一个功能,根据扥状态显示用户名/退出或者登录/注册

from .views import bp
import config
from flask import session, g
from .models import FrontUser @bp.before_request
def before_request():
""" 验证登录 """
if config.FRONT_USER_ID in session:
user_id = session.get(config.FRONT_USER_ID)
user = FrontUser.query.get(user_id)
if user:
g.front_user = user

{% if g.front_user %}
<div class="dropdown">
<a href="#" class="dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{ g.front_user.username }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">个人中心</a></li>
<li><a href="#">设置</a></li>
<li><a href="#">注销</a></li>
</ul>
</div>
{% else %}
<li><a href="{{ url_for('front.signin') }}">登录</a></li>
<li><a href="{{ url_for('front.signup') }}">注册</a></li>
{% endif %}

发布帖子js

给点击发布按钮寄一个id,方便js绑定事件

js

$(function () {
//初始化ueditor
var ue = UE.getEditor('editor', {
'serverUrl': '/ueditor/upload/'
}); $('#submit-btn').click(function (event) {
event.preventDefault();
var titleInput = $('input[name="title"]');
var boardSelect = $('select[name="board_id"]'); var title = titleInput.val();
var board_id = boardSelect.val();
var content = ue.getContent(); //详见ueditor使用说明,获取内容:http://fex.baidu.com/ueditor/#api-common ajax.post({
'url': '/apost/',
'data': {
'title': title,
'content': content,
'board_id': board_id
},
'success': function (data) {
if(data['code'] == 200){
xtalert.alertConfirm({
'msg': '发帖成功',
'cancelText': '回到首页',
'confirmText': '再发一篇',
'cancelCallback': function () {
// 点回到首页就跳转到首页
window.location = '/';
},
'confirmCallback': function () {
// 点再发一篇就清空内容
titleInput.val('');
ue.setContent('');
}
});
}else{
xtalert.alertInfo(data['message']);
}
}
});
});
});

最新文章

  1. 对Castle Windsor的Resolve方法的解析时new对象的探讨
  2. iscroll 加载不全解决方案
  3. Modelica学习
  4. Sprint回顾大揭秘——“宝典”来了
  5. MVC4在IIS6上部署遇到的问题
  6. 【LRU Cache】cpp
  7. android 退出整个程序
  8. Node.js的process模块
  9. poj 2976 Dropping tests 0/1分数规划
  10. C Static Inline函数
  11. R语言笔记3--实例1
  12. [微信小程序-开发工具]快捷键
  13. Jquery操作Table
  14. JavaWeb中使用JSON
  15. 探讨.NET Core中实现AES加密和解密以及.NET Core为我们提供了什么方便!
  16. getnameinfo函数
  17. 反序列化失败Failed to deserialize --- local class incompatible: stream classdesc serialVersionUID
  18. 安全测试&#160;WEB安全测试手册
  19. SpringCloud 学习(一) :Features
  20. 洛谷P3382 【模板】三分法(三分)

热门文章

  1. python读txt数据报编码错误
  2. C 预编译 宏 声明
  3. VM虚拟机?
  4. java 接口方法超时异常处理 设置超时时间
  5. 单元测试框架之unittest(三)
  6. for循环使用后contains方法失去效果
  7. 场效应管种类-场效应管N、P沟道与增强、耗尽型工作原理等知识详解 如何选用晶体三极管与场效应管的技巧
  8. 2018web前端面试题总结
  9. Nginx location规则匹配
  10. C# 读取、写入文件