如何对比两段代码的不同?

    <div class="modal fade" id="share-modal" tabindex="-1" role="dialog" aria-labelledby="shareModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="shareModalLabel">Permalink</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
+                    </button>
                </div>
                <div class="modal-body w-100">
                    <input class="form-control"
                           value="{{ url_for('.show_photo', photo_id=photo.id, _external=True) }}"
                           readonly>
                </div>
            </div>
        </div>
    </div>


模态框右上角多了个+号

    <div class="modal fade" id="share-modal" tabindex="-1" role="dialog" aria-labelledby="shareModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="shareModalLabel">Permalink</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body w-100">
                    <input class="form-control"
                           value="{{ url_for('.show_photo', photo_id=photo.id, _external=True) }}"
                           readonly>
                </div>
            </div>
        </div>
    </div>

改成上面这段代码,模态框正常显示,可这两段代码哪里不同呢?什么原因多了个加号?

还有这段:



@db.event.listens_for(Photo, 'after_delete', named=True)
def delete_photos(**kwargs):
    """
    Photo记录删除事件监听函数,当图片记录删除后会自动删除物理文件
    """
    target = kwargs['target']
    for filename in [target.filename, target.filename_s, target.filename_m]:
        path = os.path.join(current_app.config['ALBUMY_UPLOAD_PATH', filename])
        if os.path.exists(path):    # 如果文件存在
            os.remove(path)         # 删除文件

出现错误提示:

builtins.KeyError
KeyError: ('ALBUMY_UPLOAD_PATH', '847fe1fbdac04b4e827dc313a95d7903.jpg')

而换成如下程序:

@db.event.listens_for(Photo, 'after_delete', named=True)
def delete_photos(**kwargs):
    target = kwargs['target']
    for filename in [target.filename, target.filename_s, target.filename_m]:
        path = os.path.join(current_app.config['ALBUMY_UPLOAD_PATH'], filename)
        if os.path.exists(path):  # not every filename map a unique file
            os.remove(path)

却能正确执行,正常删除物理文件
这两段程序又有什么不同呢? 真是奇怪!!

第一处见下图:

image

第二处:中括号位置不对。

以后这种问题请使用文本对比工具处理。

(附注另一个对比工具

1 个赞

:star_struck:谢谢!!!