从首页问答标题到问答详情页

Posted yushanshan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从首页问答标题到问答详情页相关的知识,希望对你有一定的参考价值。

主PY文件写视图函数,带id参数。 

@app.route(‘/detail/<question_id>‘)
def detail(question_id):
    quest = 
    return render_template(‘detail.html‘, ques = quest)
@app.route(‘/detail/<sent_id>‘)
def detail(sent_id):
    sentt = Sent.query.filter(Sent.id == sent_id).first()
    return render_template(‘detail.html‘, sen=sentt)

首页标题的标签做带参数的链接。
      {{ url_for(‘detail‘,question_id = foo.id) }}

在详情页将数据的显示在恰当的位置。 

{{ ques.title}}
{{ ques.id  }}{{  ques.creat_time }}
{{ ques.author.username }} 
{{ ques.detail }}
{% extends ‘index.html‘ %}
<meta charset="UTF-8">
<title>
    {% block title %}
        首页
    {% endblock %}</title>
{% block head %}
    <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/shouye.css‘) }}">
{% endblock %}

{% block body %}
    <div class="all" >
        {% for foo in username %}
            <div class="wai">

                <li id="note-20391670" data-note-id="20391670" class="have-img">
                    <div class="content">
                        <div class="author">
                            <a class="avatar" target="_blank" href="/u/deeea9e09cbc">
                                <img class="img"
                                     src="//upload.jianshu.io/users/upload_avatars/1442902/b54c023e8862.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/64/h/64"
                                     alt="64">
                            </a>
                            <div class="info">
                                <a class="nickname" target="_blank" href="/u/deeea9e09cbc">{{ foo.author.username }}</a>
                                <span class="time"
                                      data-shared-at="2017-11-30T08:15:03+08:00">{{ foo.creat_time }}</span>

                            </div>
                        </div>
                        <a style="font-size: 20px" class="stitle" target="_blank"
                           href="{{ url_for(‘detail‘,sent_id=foo.id) }}">{{ foo.title }}</a>
                        <p class="abstract">
                            {{ foo.detail }}</p>
                        <div class="meta">
                            <a class="collection-tag" target="_blank" href="/c/1hjajt">{{ biaoqian }}</a>
                        </div>
                    </div>
                </li>


            </div>
        {% endfor %}
    </div>
{% endblock %}

建立评论的对象关系映射:

class Comment(db.Model):
    __tablename__=‘comment

class Comment(db.Model):
    __tablename__ = ‘comment‘
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    author_id = db.Column(db.Integer, db.ForeignKey(‘user.id‘))
    sent_id = db.Column(db.Integer, db.ForeignKey(‘sent.id‘))
    creat_time = db.Column(db.DateTime, default=datetime.now)
    detail = db.Column(db.TEXT, nullable=False)
    sent = db.relationship(‘Sent‘, backref=db.backref(‘comment‘))
    author = db.relationship(‘User‘, backref=db.backref(‘comment‘))

 

 

以上是关于从首页问答标题到问答详情页的主要内容,如果未能解决你的问题,请参考以下文章

从首页问答标题到问答详情页

从首页问答标题到问答详情页

从首页问答标题到问答详情页

从首页问答标题到问答详情页

从首页问答标题到问答详情页

从首页问答标题到问答详情页