inyfee
V2EX  ›  Django

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

  •  
  •   inyfee · May 31, 2016 · 3518 views
    This topic created in 3717 days ago, the information mentioned may be changed or developed.

    我在 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 replies    2016-05-31 01:33:49 +08:00
    menc
        1
    menc  
       May 31, 2016
    这是 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  
       May 31, 2016
    @menc 不是 tuple ,是 dict 更正一下
    inyfee
        3
    inyfee  
    OP
       May 31, 2016
    @menc 2 年多没写 py 啦,汗颜。 我知道是 string format ,只是没这么用过。
    谢谢指点。
    这个 django 项目是 2 年多前写的,后来就维护一下。然后就没怎么搞了。囧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5562 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:51 · PVG 14:51 · LAX 23:51 · JFK 02:51
    ♥ Do have faith in what you're doing.