Chapter 3:Code Style in Django

• Django coding style
• Using IDE for Django web development
• Django project structure
• Best practices—using version control
• Django rescue team (where to ask Django questions)
• Faster web development—using Twitter-Bootstrap

The Django project structure
$ django-admin.py startproject django_mytweets

Paste_Image.png

manage.py: This is utility script is used to manage our project. You can think of it as your project's version of django-admin.py. Actually, both django-admin.py and manage.py share the same backend code.

settings.py 参数说明:

  • DEFAULT_APPS: This parameter contains the default Django installedapplications (such as the admin)
  • THIRD_PARTY_APPS: This parameter contains other application likeSocialAuth used for social authentication
  • LOCAL_APPS: This parameter contains the applications that arecreated by you
Best practices - using version control

Let's take a look at the following commands and their uses(git常用命令):

  • $git add <file-name> or $git add: For adding all files to the staging area in bulk.
  • $git status: To know the status of your working directory, which files have been added, and which files have not been added.
  • $git diff: To get the status of what is modified and staged, or what is modified and has not been staged.
  • $ git commit -m: To commit the changes made, first you have to add them to the staging area; then, you have to commit them using this command.
  • $ git rm <file-name>: If you have mistakenly added any file to the staging area, you can remove it from the staging area by using this command.
  • $git stash: Git doesn't track the renamed files. In other words, if you have renamed already staged files, you will have to add them again to the staging and then commit. You can save the changes by not actually committing to the repository by using the following command.
  • $git stash apply: It takes all the current changes and saves it to the stack. Then, you can continue working with your changes. Once you are in a position to get your saved changes, you can do so using this command.

分支

  • $git branch: To list an existing branch using Git, we need to use this command.

Paste_Image.png

  • $git checkout -b <new-branch-name>: A new branch can be created in the existing repository using this command. We can see logically how it looks with the help of the following block diagram:

Paste_Image.png

You will get a message informing you that you have switched to the new branch. If you want to switch back to the old branch, you can use the following command:

  • $git checkout <old-branch-name>: You will see the message Switched to branch <old-branch-name>.
  • $git merge <branch-name>: After the feature is complete, you can merge it to the branch of your choice using this command. This will merge the
    branch <branch-name> to your current branch. To sync the changes back to
    the <branch-name>, you can check out from your current branch to the
    branch <branch-name> and merge again. You can also mark the important points in your commit history by using tags.
  • After the commit, you can tag an important commit by using the $git tag-a v1.0 command.
  • To get new changes from the remote server, you can fetch the changes from Git using the $git fetch command.
  • To merge the changes directly to your current branch, you can use the $git pull command.
  • After you are done with your changes, you can commit and push them to the remote repository using the $git push command.

运行服务,切换到根目录下执行如下语句:

$ python3 manage.py runserver 8080
时间: 2024-10-03 20:18:27

Chapter 3:Code Style in Django的相关文章

样式表(CSS:Cascading Style Sheets)[中]

css|样式表 样式表(CSS:Cascading Style Sheets)学习[上] 七.CSS1属性<?XML:NAMESPACE PREFIX = O /> 3.1  font属性        字模.字体样式.字体大小.字体效果等.常用属性有: ① font-family:字模,Cursive.Fantasy.Comic Sans MS等. ② font-size:字体物理大小或相对大小,物理大小包括:xx-small.x-small.small.medium.large.x-lar

样式表(CSS:Cascading Style Sheets)学习[上]

css|样式表 一.样式表基础 1. 样式表中每一个条目由选择符(selector)和对应的规则组成,选择符通常是HTML元素名称,也可以是类(class).标识符(id).伪类(pseudo class,它们标示了超链接的不同状态)等. 2. 将样式表(规则)添加到HTML文档中有3种方式: ① 外部样式表. ② 应用于整个文档的样式,位于<head>区,包括嵌入样式表和输入样式表. ③ 行内样式,通过绝大多数元素的style属性实现. 3. 样式表内的注释用/* -*/.通过将样式规则包围

样式表(CSS:Cascading Style Sheets)简要教程[下]

css|教程|样式表 七.CSS1属性 3.1  font属性        字模.字体样式.字体大小.字体效果等.常用属性有: ① font-family:字模,Cursive.Fantasy.Comic Sans MS等. ② font-size:字体物理大小或相对大小,物理大小包括:xx-small.x-small.small.medium.large.x-large.xx-large分别对应1-7号字体. ③ font-style:是否斜体, normal.italic.oblique(

样式表(CSS:Cascading Style Sheets)简要教程[上]

css|教程|样式表 一.样式表基础   1. 样式表中每一个条目由选择符(selector)和对应的规则组成,选择符通常是HTML元素名称,也可以是类(class).标识符(id).伪类(pseudo class,它们标示了超链接的不同状态)等. 2. 将样式表(规则)添加到HTML文档中有3种方式: ① 外部样式表. ② 应用于整个文档的样式,位于<head>区,包括嵌入样式表和输入样式表. ③ 行内样式,通过绝大多数元素的style属性实现. 3. 样式表内的注释用/* -*/.通过将样

HDU 3461:Code Lock(并查集+二分求幂)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=3461 原题: Problem Description A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wheels. Each wheel has the 26 letters of the English alphabet 'a' through 'z',

热潮:“航母Style”全民狂欢

2005年8月,被世人遗忘已久的"瓦良格"号,被人发现换上了中国海军标准的"海军灰"涂装,出现在大连造船厂驳船码头.改装工作正式开始. 2011年8月10日,经过6年改装的"辽宁"号出港,依靠自己的动力,进行了第一次海试.国内的"航母热"迅速升温,无论是对于未来中国航母及其战斗群配属力量的讨论,还是国家形象与战略影响的话题,都在被以各种方式持续发酵. 然而,有关中国首艘航母的消息,虽然http://www.aliyun.com

Chapter 02:复合 VS 继承

复合优先于继承,继承是实现代码重用的有力手段,并不是所有情况都适用,使用不当会导致软件变得很脆弱.与方法调用不同的是,继承打破了封装性. 总而言之,组合和继承,都能实现对类的扩展.但是要分具体情况用哪个实现,是Has-a,还是Is-a的关系. 两者区别如下表所示: 组合  继承 has-a关系 is-a关系 运行期决定 编译期决定 不破坏封装,整体和局部松耦合 破坏封装,子类依赖父类 支持扩展,随意增加组合类 只能继承一个父类,必须包含所有方法,增加系统复杂性 动态选择组合类方法 复用父类方法

Code Style(代码的风格)

1.简介 2.什么是风格? 3.代码的风格为什么如此重要? 4.更少的工作,更多的文档? 5.推荐的代码风格 6.简单的文档 7.输出风格 8.结论 简介 让我们面对一下吧-如果您是一个资深的程序员,那么您总是在最后期限下工作并且您的最终目标是完成您设计的软件.如果您是个新手,您的努力是更多的研究.试验.当然还有错误和一心希望您的程序可以象打算的那样运行.不管怎样,当您的程序真的如愿以偿的运行时那种成功的感觉令人十分振奋,但更多的程序员发现能够用良好的风格生成程序内部代码时的那种自豪的感觉更棒.

css优先级探讨

这篇文章是对于CSS优先级的探讨,您是否能熟练使用了呢? css优先级的四大原则: 原则一: 继承不如指定 如果某样式是继承来的永远不如具体指定的优先级高. 例子1: CODE: <style type="text/css"> <!-- *{font-size:20px} .class3{ font-size: 12px; } --> </style> <span class="class3">我是多大字号?</