程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[getting started with Django] 13 page Association MySQL multi field table (check)

編輯:Python

Add a few lines MySQL User information

insert into app01_userinfo(name,password,age,account,create_time,gender,depart_id)values(" Liu Dong ","123",23,100.68,"2010-11-11",1,1);
insert into app01_userinfo(name,password,age,account,create_time,gender,depart_id)values(" Han Chao ","666",23,100.68,"2001-01-11",2,1);
insert into app01_userinfo(name,password,age,account,create_time,gender,depart_id)values(" Zhu hufei ","123",23,9900.68,"2021-05-11",1,3);

With python Syntax get database value

  • Date to string , Use strftime(), The meaning of parameters in brackets can be Baidu
  • Outreach field (ForeignKey),Django Support to return an object
    for example depart.id = depart_id;depart.title = depart_id stay Department Corresponding to title
  • The number defined by the array ,Django Provide functions ,obj.get_???._display(), Get the original value

With html Template syntax gets database values

Be careful : Template syntax should never be bracketed (Django Will be backstage at the right time , Automatically bracketed )

  • Pay attention to the template syntax , Writing method of date to string
  • get_gender_display Don't put parentheses after

source :BV1NL41157 Wu Peiqi 《2022 B Station the most detailed django3 course (django From introduction to practice )》P30


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved