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 ...

• 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
目录
相关文章
|
8月前
|
JSON 数据库 数据格式
Django之Form组件
Django之Form组件
|
数据库 数据安全/隐私保护 Python
|
Python
django -- ContentType
django -- ContentType
|
8月前
|
数据库 开发者 UED
如何使用Django的Form组件
如何使用Django的Form组件
89 0
|
前端开发 数据库 Python
Django Web 极简教程(六)- Django Form(Part A)
Django Web 极简教程(六)- Django Form(Part A)
Django Web 极简教程(六)- Django Form(Part A)
|
Python
Django的Content-Type组件
一、需求 现在我们有这样一个需求~我们的商城里有很多的商品,节日要来了,我们要搞活动。那么我们就要设计优惠券,优惠券都有什么类型呢,满减的、折扣的、立减的。
1207 0
|
前端开发 JavaScript 数据库
Django中的Form组件
一、form组件的主要功能: 生成页面的HTML标签及样式 对用户提交的数据进行校验 自动生成错误信息 保留上次输入信息 二、使用form组件实现注册功能 1、在Django项目下创建一个文件夹,在文件夹中创建一个朋友文件,名字随便起,之后在py文...
1387 0
|
前端开发 数据库 数据安全/隐私保护
第21天,Django之Form组件
ModelForm 请参考官方文档 一、Form组件初识 参考博客一 武沛奇老师博客参考博客二 Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 models.
1200 0