48 - 个人博客项目-19 - 用户中心(关于我) && 首页关于我

一. 用户中心- 关于我设置

1. templates / user / center.html 填充用户中心关于我的设置html
<!--        关于我的设置-->
          <div class="right1" style="padding-top:30px;">
                <form action="{{ url_for('user.about_me') }}" method="post" enctype="multipart/form-data">
                    <p>
                        <textarea name="about" class="mytextarea">
 
                        </textarea>
                    </p>
                    <p></p>
                    <p style="text-align:right;">
                        <button type="submit" class="btn btn-primary">更改我的</button>
                    </p>
 
                </form>
            </div>
2. apps / user /view.py 编写关于我的函数
# 关于用户介绍添加
@user_bp.route('/aboutme', methods=["GET", "POST"])
def about_me():
    content = request.form.get("about")
    # 添加信息
    try:
        aboutme = AboutMe()
        # 模型类型为BLOB二进制,需要转成二进制才能成功储存
        # 或者模型类型改为TEXT,数据库类型为BLOB
        aboutme.content = content.encode("utf-8")
        aboutme.user_id = g.user.id
        db.session.add(aboutme)
        db.session.commit()
 
    except Exception as err:
        return redirect(url_for('user.user_center'))
    else:
        return render_template('user/aboutme.html', user=g.user)

二 . 首页 - 关于我页面

1.  templates / user / aboutme.html 新建关于我页面
        (1). 继承公共模板
{% extends 'base.html' %}
{% block title %}
    关于我
{% endblock %}
        (2). 编写样式
{% block styles %}
    {{ super() }}
    <style>
        #container {
            width: 1000px;
            margin: 0 auto;
        }
 
        #container p {
            width: 80%;
            background-color: #83cae3;
        }
    </style>
{% endblock %}
        (3). 编写页面
{% block newcontent %}
    <div id="container">
        <p>
            {% if not user.about %}
                用户中心设置更多关于我的信息~~~
            {% else %}
                {{ user.about[0].content | cdecode1 | safe }}
            {% endif %}
 
        </p>
    </div>
{% endblock %}
2. apps / user / view.py 编写关于我函数
# 关于我页面展示
@user_bp.route("/showabout")
def show_about():
    return render_template("user/aboutme.html", user=g.user)
3. base.html 配置关于我的路由
<li><a href="{{ url_for('user.show_about') }}">关于我</a></li>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值