windows powershell/linux run manage.py(Django) without typing python ahead在命令行中将python(.py)文件作为脚本运行

powershell run manage.py without type python ahead

preface

这里(下方的讨论)以django项目中的manage.py脚本文件为例

for windows

设置打开.py文件的默认行为

  • (选择python解释器打开)
  • 如果是GUI编辑器,就达不到效果(当你用manage.py打头,powershell会尝试启动编辑器打开manage.py,这不是我们想要的)
    在这里插入图片描述
效果

我在powershell下跑一段测试
在这里插入图片描述

省略掉后缀py

配置PathExt环境变量

;py加入到该变量取值序列中

  • 这将使得系统能够在你不给出后缀的情况下尝试判断环境变量PathExt中的后缀取值序列
    在这里插入图片描述

在这里插入图片描述

for linux

  • 在linux中想要省略掉python这个单词很简单,只需要配置别名即可
    譬如:alias manage='python manage.py'
posted @ 2022-05-21 09:40  xuchaoxin1375  阅读(18)  评论(0)    收藏  举报  来源