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
目录
相关文章
|
数据库 数据安全/隐私保护 Python
|
JSON 数据库 数据格式
[Python]Django 视图(View)和URL 与 模板(Template)
[Python]Django 视图(View)和URL 与 模板(Template)
【Flask】flask-bootstrap报错AttributeError: module ‘dominate.tags‘ has no attribute ‘input‘解决方法
【Flask】flask-bootstrap报错AttributeError: module ‘dominate.tags‘ has no attribute ‘input‘解决方法
如何使用flask的 @app.url_value_preprocessor 装饰器
如何使用flask的 @app.url_value_preprocessor 装饰器
|
前端开发 数据库 Python
Django Web 极简教程(六)- Django Form(Part A)
Django Web 极简教程(六)- Django Form(Part A)
Django Web 极简教程(六)- Django Form(Part A)
|
Python
Django的Content-Type组件
一、需求 现在我们有这样一个需求~我们的商城里有很多的商品,节日要来了,我们要搞活动。那么我们就要设计优惠券,优惠券都有什么类型呢,满减的、折扣的、立减的。
1200 0
|
数据库 Python
Django setting.py添加app
在django创建app中,修改models.py添加对应的数据库表,后执行 makemigrations Mynewsite 提示: App Mynewsite could not be found.
1446 0
|
数据格式 Python
Django model update的各种用法介绍
Django开发过程中对表(model)的增删改查是最常用的功能之一,本文介绍笔者在使用model update过程中遇到的那些事 [ 运行环境:Django2.0 ] model update常规用法 假如我们的表结构是这样的 class User(models.
1555 0