zoukankan      html  css  js  c++  java
  • 从首页问答标题到问答详情页

      1. 主PY文件写视图函数,带id参数。 
        @app.route('/detail/<question_id>')
        def detail(question_id):
            quest = 
            return render_template('detail.html', ques = quest) 
      2. 首页标题的标签做带参数的链接。
              {{ url_for('detail',question_id = foo.id) }}

      3. 在详情页将数据的显示在恰当的位置。 
        {{ ques.title}}
        {{ ques.id  }}{{  ques.creat_time }}
        {{ ques.author.username }} 
        {{ ques.detail }}
      4. 建立评论的对象关系映射:

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

      5.  尝试实现发布评论。

    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'))
        question_id=db.Column(db.Integer,db.ForeignKey('question.id'))
        detail=db.Column(db.Text,nullable=False)
        creatTime=db.Column(db.DateTime,default=datetime.now)
        question=db.relationship('Question',backref=db.backref('comments',order_by=creatTime.desc))
        author=db.relationship('User',backref=db.backref('comments'))
    <div class="detail">
        <div class="detail_left">
    
        <h2>{{ question.title }}</h2>
        <a class="username">{{ question.author.username }}</a>
        <span class="badge">{{ question.creatTime }}</span>
        <hr>
        <a style="white-space: pre-wrap"  >{{ question.detail }}</a>
        <hr>
        <form action="{{ url_for('comment') }}" method="post">
        <textarea name='detail' class="form-control" rows="6" id="Detail"></textarea>
        <br><button class="btn-default">发布</button>
         </form>
        <p>评论:({{ question.comments|length }})</p>
        <ul class="comment">
            {% for foo in question.comments %}
            <span class="icon" aria-hidden="true"></span>
            <a href="#" class="name">{{ foo.author.username }}</a>
             <span class="badge2">{{ foo.creatTime }}</span>
               <br>
            <p class="neirong">{{ foo.detail }}</p>
    
            {% endfor %}
        </ul>
    
    
    </div>
    </div>
    </body>
  • 相关阅读:
    Servlet基本概念及其部署
    MSSQL数据库全库批量替换
    我的第一个GAE(google appengine)应用
    今天你有病了吗?
    [Microsoft][ODBC SQL Server Driver][DBNETLIB] 一般性网络错误
    Google appengine 上传输错用户名解决办法;
    查看畸形文件
    Session
    jq幻灯片2
    JS打开层/关闭层/移动层动画效果
  • 原文地址:https://www.cnblogs.com/0055sun/p/8000511.html
Copyright © 2011-2022 走看看