Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - 为什么我注释所有cips变量,但仍然收到错误“ jinja2.exceptions.UndefinedError:'cips'未定义”?(Why do I comment all the cips variables and still get an error“jinja2.exceptions.UndefinedError: 'cips' is undefined”?)

I encounter "Object of type 'Response' is not JSON serializable" which may cause by var cips when I am developing an article comment using flask.So I comment all cips,however,Pycharm still report error "jinja2.exceptions.UndefinedError: 'cips' is undefined", I really don't understand.

(我在使用flask开发文章注释时遇到“类型'Response'的对象不可JSON序列化”这可能是由var cips引起的。所以我注释了所有cips,但是,Pycharm仍然报告错误“ jinja2.exceptions.UndefinedError:” cips'未定义”,我真的不明白。)

Didn't I comment all the cips variables?

(我没有注释所有cips变量吗?)

Here is my html code(as you will see,I comment all cips)

(这是我的html代码(如您所见,我注释所有cips))

{% extends "base.html" %}

{% block title %}
    {{ article.title }}-Article
{% endblock %}

{% block content %}
<div class="articlePage">
        Title:{{ article.title }}<br/>
        PostTime:{{ article.postTime }}<br/>
        Email:{{ user.email[0]+"***"+user.email[user.email.index('@'):] }}<br/>
        Abstract:{{ article.abstract }}<br/>
        Highlight Part:{{ article.highlight_part }}<br/>
        Download Link:<a href="../{{ article.dl_link }}">download</a>
        <button><a href="../upvote/{{ article.id }}">up:{{ article.upvoteNum }}</a></button>
        <button><a href="../downvote/{{ article.id }}">down:{{ article.downvoteNum }}</a></button>
 </div>
<div class="post comment" >
    <form action="/{{ article.id }}/comment" method="post"  id="form">
         Email:<input type="email" name="email" required><br/>
         Content:<br/> <textarea name="content" id="" cols="30" rows="10"></textarea><br/>
    </form>
    <input type="text" id="code" disabled>
    <input type="text" id="input">
    <button onclick="validate()">submit</button>
    <script>
        // var cips=[];
    </script>
</div>
 <div class="comment" >
 <h1>COMMENTS</h1>
     <div id="div"></div>
    {% for i in range(0,comments |length) %}
        {% set comment=comments[i] %}
<!--        {% set cip=cips[i] |tojson %}-->
<!--        {% set commentState=cips[i].vote_state%}-->
        <p>{{ loop.index }}. Email:{{ comment.email }}</p>
        <p>PostTime:{{ comment.postTime }}</p>
        <p>Content:{{ comment.content }}</p>

        <div id="vote_div">

        </div>
        {% set up_btn_id='up_btn'~ i|string %}
        {% set down_btn_id='down_btn'~ i|string %}
     <script>
         // cips.push('{{cips[i]}}');
         //     commentState="{{ cips[i].vote_state}}";
         //     console.log(commentState);
         //     console.log('{{up_btn_id}}')
        </script>
<!--        {% if cip.vote_state ==0 %}-->
<!--            <button id='{{up_btn_id}}' onclick="upVote(this)">up:{{ comment.upvoteNum }}</button>-->
<!--&lt;!&ndash;        <button><a href="../cupvote/{{ comment.id }}">up:{{ comment.upvoteNum }}</a></button>&ndash;&gt;-->
<!--            <button id="{{down_btn_id}}" onclick="downVote(this)">down:{{ comment.downvoteNum }}</button>-->
<!--&lt;!&ndash;        <button><a href="../cdownvote/{{ comment.id }}">down:{{ comment.downvoteNum }}</a></button>&ndash;&gt;-->
<!--        {% elif cip.vote_state ==1 %}-->
<!--            <button id='{{up_btn_id}}' onclick="upVote(this)" style="color: green">up:{{ comment.upvoteNum }}</button>-->
<!--            <button id="{{down_btn_id}}" onclick="downVote(this)">down:{{ comment.downvoteNum }}</button>-->
<!--        {% else %}-->
<!--            <button id='{{up_btn_id}}' onclick="upVote(this)">up:{{ comment.upvoteNum }}</button>-->
<!--            <button id="{{down_btn_id}}" onclick="downVote(this)" style="color: red">down:{{ comment.downvoteNum }}</button>-->
<!--        {% endif %}-->


        {% if flag==1 %}
            <form action="../cdelete/{{ comment.id }}" method="post">
                Password:<input type="password" name="psw">
                <input type="submit" value="delete">
            </form>
        {% endif %}
    {% endfor %}

 </div>
{% endblock %}

This is python (I also not pass cips )

(这是python(我也没有通过cips))

@app.route('/article/<article_id>')
def article(article_id):
    article = articleService.find_by_id(article_id)
    user = userService.find_by_id(article.user_id)
    ip = ipService.find_ip_by_ip(request.remote_addr)
    aip = ipService.find_aip_both(article_id, ip.id)
    comments = commentService.find_by_articleid(article_id)
    comments.reverse()
    # find all comment state related to this ip
    cips=[]
    for index in range(0,len(comments)):
        cips.append(jsonify((ipService.find_cip_by_both(comments[index].id,ip.id)).as_json()))

    if aip is None:  # 第一次访问
        aip = ArticleIp(ip_id=ip.id, article_id=article_id, vote_state=0)
        ipService.insert(aip)
        articleService.addAccess(article)
    # todo what the response means?
    return render_template('article.html', article=article, user=user, comments=comments, flag=0)
  ask by user9782872 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...