V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yeelone
V2EX  ›  Django

djangoUeditor 源码中这一句是什么意思 ?

  •  
  •   yeelone · 2016-05-31 00:57:14 +08:00 · 2794 次点击
    这是一个创建于 2879 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在 django 后台中使用了 djangoueditor,以前一直好好的,没有出过什么问题。 之后有一次环境重新安装,突然发现附件无法上传了。

    通过看源码,我发现是这一段有问题:

       #取得输出文件的路径
       OutputPathFormat=(request.GET.get(path_format,USettings.UEditorSettings["defaultPathFormat"]) % path_format_var).replace("\\","/")
       
    

    github 地址: https://github.com/zhangfisher/DjangoUeditor/blob/master/DjangoUeditor/views.py

    我发现是因为函数中没有得到文件名,所以导致无法保存上传的附件。 我想问的是,上面那一句中, % 的作用是什么 ?这样写是什么意思?

    3 条回复    2016-05-31 01:33:49 +08:00
    menc
        1
    menc  
       2016-05-31 01:04:29 +08:00
    这是 python 中最基本的 string format ,你真的是写 pythond 的么。。。
    settings.py 中, defaultPathFormat 是这么定义得。
    "defaultPathFormat":"%(basename)s_%(datetime)s_%(rnd)s.%(extname)s"

    加上%,再加上你的 path_format_var 的 tuple 正好组成一个 formatted string
    menc
        2
    menc  
       2016-05-31 01:05:12 +08:00
    @menc 不是 tuple ,是 dict 更正一下
    yeelone
        3
    yeelone  
    OP
       2016-05-31 01:33:49 +08:00
    @menc 2 年多没写 py 啦,汗颜。 我知道是 string format ,只是没这么用过。
    谢谢指点。
    这个 django 项目是 2 年多前写的,后来就维护一下。然后就没怎么搞了。囧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5278 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.