V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Etuloser
V2EX  ›  Python

请教个关于 cookiecutter 的正确使用方式问题

  •  
  •   Etuloser · 108 天前 · 776 次点击
    这是一个创建于 108 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://github.com/cookiecutter/cookiecutter
    cookiecutter 主要用来生成项目模版,在初始化的同时填入一些变量来替换掉模版中预填的值。

    我在实际使用过程中主要遇到以下问题:
    由于一些关键文件的代码使用`{{}}`的形式预填值,导致直接运行项目的时候无法正常启动,给后续调试更新带来困难。

    有什么好的方法解决嘛,或者有其他的工具可以实现这个功能嘛。

    这个是我的仓库:
    https://github.com/Etuloser/fastapi-clean-template
    6 条回复    2024-01-12 09:14:08 +08:00
    Alias4ck
        1
    Alias4ck  
       108 天前
    https://github.com/cookiecutter/cookiecutter/issues/1088#issuecomment-416183503

    ```
    {{ this_will_be_rendered }}

    {% raw %}
    {{ this_will_not }}
    {% endraw %}
    ```
    Etuloser
        2
    Etuloser  
    OP
       108 天前
    @Alias4ck 不知道是否是我表述不清楚,我的意思是 cookiecutter 会侵入源代码导致项目整体无法运行,必须使用生成后的代码才能正常运行

    比如在 DRF 模版中,路由文件如下:
    https://github.com/Etuloser/cookiecutter-DRF/blob/main/%7B%7B%20cookiecutter.project_slug%20%7D%7D/src/urls.py

    这个时候直接运行项目肯定是会报错的,但是我又不想生成一个项目来调试,而是直接调试我的模版。
    alexsz
        3
    alexsz  
       108 天前
    @Etuloser 用正则检查? re.match(r'\{\{ ?cookiecutter\.*? ?\}\}')
    Alias4ck
        4
    Alias4ck  
       108 天前
    那你是想 debug jinja template render 咯?
    saber000
        5
    saber000  
       107 天前   ❤️ 1
    可以基于这个工具来搞 https://github.com/cruft/cruft
    修改模板-->同步到最终项目-->运行调试-->回头修改模板
    Etuloser
        6
    Etuloser  
    OP
       106 天前
    @saber000 谢谢,可以一定程度上解决这个问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2757 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:25 · PVG 13:25 · LAX 22:25 · JFK 01:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.