Django官方教程实践

公司的网关服务使用Django开发的,自己开发微服务组件都要在网关上封装API接口,但是Django封装了http、db操作,导致自己在debug或开发上难以下手,所以学习了下Django,下面记录下学习过程。

Django Tutorial

  1. 路由如何分配
  2. 数据库如何配置

db migration

  1. python manage.py makemigrations 根据模型的变化生成migrations,
  2. python manage.py migrate 将migrations应用到数据库

shell

django在创建models后会生成相关model处理(CRUD、过滤查询等)的api,可以通过shell与db交互,breference

➜  mysite python manage.py shell
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.models import Question, Choice
>>> Question.objects.all();
[]

django admin

test account

admin

abc@def.com

abS34d4DS

page structure

https://docs.djangoproject.com/en/2.0/intro/tutorial03/

A URL pattern is simply the general form of a URL - for example: /newsarchive///.

To get from a URL to a view, Django uses what are known as ‘URLconfs’. A URLconf maps URL patterns to views.

This tutorial provides basic instruction in the use of URLconfs, and you can refer to URL dispatcher for more information.

TBD...

comments powered by Disqus