BBS论坛(二十六)
2025年01月15日 02:41:42

LIKE.TG | 发现全球营销软件&服务汇聚顶尖互联网营销和AI营销产品,提供一站式出海营销解决方案。唯一官网:www.like.tg
26.发布帖子前台代码逻辑完成
(1)front/hooks.py
from .views import bp
from flask import session,g
from .models import FrontUser
import config
@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
(2)front/init.py
from . import hooks
(3)front/front_base.html
<ul class="nav navbar-nav navbar-right">
{% if g.front_user %}
<li class="dropdown">
<a 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>
</li>
{% else %}
<li><a href="{{ url_for('front.signin') }}">登录</a></li>
<li><a href="{{ url_for('front.signup') }}">注册</a></li>
{% endif %}
</ul>
(4)front/apost.js
$(function () {
var ue = UE.getEditor('ueditor', {'serverUrl': '/ueditor/upload/'});
$('#submit-btn').on('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();
zlajax.post({
'url': '/apost/',
'data': {
'title': title,
'board_id': board_id,
'content': content
},
'success': function (data) {
if (data['code'] == 200) {
zlalert.alertConfirm({
'msg': '帖子发表成功',
'cancelText': '返回首页',
'confirmText': '再写一篇',
'cancelCallback': function () {
window.location = '/';
},
'confirmCallback': function () {
titleInput.val('');
ue.setContent('');
}
});
} else {
zlalert.alertInfo(data['message']);
}
}
})
});
});
(5)config.py
UEDITOR_UPLOAD_PATH=os.path.join(os.path.dirname(__file__),'images')

LIKE.TG:汇集全球营销软件&服务,助力出海企业营销增长。提供最新的“私域营销获客”“跨境电商”“全球客服”“金融支持”“web3”等一手资讯新闻。
点击【联系客服】 🎁 免费领 1G 住宅代理IP/proxy, 即刻体验 WhatsApp、LINE、Telegram、Twitter、ZALO、Instagram、signal等获客系统,社媒账号购买 & 粉丝引流自助服务或关注【LIKE.TG出海指南频道】、【LIKE.TG生态链-全球资源互联社区】连接全球出海营销资源。
本文由LIKE.TG编辑部转载自互联网并编辑,如有侵权影响,请联系官方客服,将为您妥善处理。
This article is republished from public internet and edited by the LIKE.TG editorial department. If there is any infringement, please contact our official customer service for proper handling.
Server deployment全球论坛人工智能论坛全球峰会发展论坛战略论坛开放论坛程序员论坛互联网峰会科技峰会