Code Monkey home page Code Monkey logo

djangoshortcuts's Introduction

djangoshortcuts

提供一个全局命令,用于方便快捷生成模板等相关文件。

安装

通过 PYPI 安装(推荐)

pip install djangoshortcuts

通过源码安装

python setup.py install

使用方式

在安装成功之后,获得一个全局命令:dj,通过 dj -h 可以查看到该命令的使用方式

$dj -h
usage: dj [-h] --app APP [-a ADD] [-t TEMPLATE] [-s STATIC]

Easily to create files when using django

optional arguments:
  -h, --help            show this help message and exit
  --app APP             input the app name which django created
  -a, --add ADD         add file automatically, the value must be one of
                        ['forms', 'urls']
  -t, --template TEMPLATE
                        add templates html files
  -s, --static STATIC   add static files

You must cd BASE_DIR to run this script

全局命令备忘查询

有时候忘记安装这些模块都提供了哪些全局命令,可以通过以下这种方式查询。

$python -m djangoshortcuts -h
Please use command [dj -h] for the detail.

举例说明

下面简要举例说明这个命令的使用方式,其实看上面的 usage 就可以明白九成以上了。

假设 django app 名称为 polls, 首先需要切换到网站的根目录下,就可以运行以下命令

  1. 生成 forms.py 或者 urls.py 文件

    dj --app polls -a forms
    dj --app polls -a urls
    
  2. 生成 index.html 文件

    dj --app polls -t index.html
    

    该命令会自动创建 polls/templates/polls 相关的文件夹,并生成 polls/templates/polls/index.html 文件

  3. 生成 style.css 文件

    dj --app polls -s style.css
    

    该命令会自动创建 polls/static/polls 相关的文件夹,并生成 polls/static/polls/style.css 文件

  4. 考虑到静态文件夹下常增加 css 和 js 文件夹来管理相关静态文件,所以在 -s 参数的行动逻辑多增加一个功能

    dj --app polls -s css/style.css
    

    该命令和 3 的区别在于,文件的路径为 polls/static/polls/css/style.css,相关的文件夹会自动创建

    dj --app polls -s js/login.js
    

    同样地,文件的路径为 polls/static/polls/js/login.js

后记

以上参数中,--app 是必选参数,除此之外的参数都是可选参数并且不互斥。也就是说添加文件的时候,不同的参数可以同时进行。

djangoshortcuts's People

Contributors

suifengpiaoyang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.