Home Backend Development Python Tutorial 简单介绍Python的Django框架的dj-scaffold项目

简单介绍Python的Django框架的dj-scaffold项目

Jun 06, 2016 am 11:18 AM
django python

由于Django没有象rails一样指定项目的目录结构规范,很多人都对django项目的目录结构要如何组织而感到困惑。为此我又新创建了一个开源项目dj-scaffold(django的脚手架)。这个项目用于自动生成一个标注化的django项目和app。

项目地址:https://github.com/vicalloy/dj-scaffold
安装

已经发布到了pypi,所以你可以用pip或easy_install 来进行安装。

pip install dj-scaffold 
easy_install dj-scaffold
 
Copy after login

使用

dj-scaffold主要提供了两个命令,dj-scaffold.py和lbstartapp。
dj-scaffold.py

该脚本用于取代django的startproject命令。使用方式如下:

dj-scaffold.py projectname 
 
Copy after login

在该命令执行后,将创建项目projectname。在项目的scripts目录中提供了脚本create_env.py和env.rc。

  • create_env.py 执行该脚本将自动初始化python虚拟环境。新生成的python虚拟环境在env目录。
  • env.rc 该脚本用户启动python虚拟环境(source env.rc)。该脚本同时为python manage.py设置了快捷方式$mg。你可以在任何目录调用$mg来执行django命令。比如你用$mg runserver来启动测试服务器。

项目对应的目录结构如下:

注:文件太多,去掉了部分不重要的文件


dj-scaffold.py projectname 

|+docs/  #用于存放项目的相关文档
|+env/   #python虚拟环境,由脚本自动生成
|~requirements/   #第三方依赖包的存放位置
| `-requirements.pip  #pip的依赖说明文件
|~scripts/  #系统相关的脚本
| |-create_env.py  #创建python虚拟环境(env目录)
| `-env.rc  #进入python虚拟环境。同时提供python manger.py的快捷方式$mg。可在任意目录使用$mg。
|~sites/  #Django的项目文件。在settings文件中增加了部分默认配置。如数据库默认使用sqlite,设置项目的模板以及静态文件目录。
| |+media/  #项目静态文件(用户上传)
| |+static/  #项目静态文件(css、js等)
| `+templates/  #项目模板
|+tools/  #一些项目依赖的第三方工具包。如python虚拟环境初始化脚本等。
`~wsgi/  #项目部署用的wsgi文件
 `-dj_scaffold.wsgi

Copy after login


lbstartapp

lbstartapp作为django的扩展命令提供。将dj_scaffold加到INSTALLED_APPS后即可使用该命令。该命令将生成一个标准的app,相比django自带的startapp,lbstartapp将那些不太常用的app默认目录也都给生成了出来。对应目录结构如下:

|+management/  #命令目录 
|+static/  #静态文件目录 
|+templates/  #模板目录 
|+templatetags/  #tag目录 
|-__init__.py 
|-admin.py  #admin管理后台的models配置文件 
|-forms.py 
|-models.py 
|-settings.py  #app自己的settings文件 
|-tests.py 
|-urls.py  #urls配置文件 
`-views.py
 
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to download deepseek Xiaomi How to download deepseek Xiaomi Feb 19, 2025 pm 05:27 PM

How to download deepseek Xiaomi

What are the advantages and disadvantages of templating? What are the advantages and disadvantages of templating? May 08, 2024 pm 03:51 PM

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step May 06, 2024 pm 03:52 PM

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks Share several .NET open source AI and LLM related project frameworks May 06, 2024 pm 04:43 PM

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis A complete guide to golang function debugging and analysis May 06, 2024 pm 02:00 PM

A complete guide to golang function debugging and analysis

How do you ask him deepseek How do you ask him deepseek Feb 19, 2025 pm 04:42 PM

How do you ask him deepseek

How to save the evaluate function How to save the evaluate function May 07, 2024 am 01:09 AM

How to save the evaluate function

See all articles