① Django怎麼多表聯合查詢
先讓我們回憶一下在第五章里的關於書本(book)的數據模型:
1
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __unicode__(self):
return self.name
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
def __unicode__(self):
return self.title
如我們在第5章的講解,獲取資料庫對象的特定欄位的值只需直接使用屬性。 例如,要確定ID為50的書本的標題,我們這樣做:
>>> from mysite.books.models import Book
>>> b = Book.objects.get(id=50)
>>> b.title
u'The Django Book'
但是,在之前有一件我們沒提及到的是表現為ForeignKey 或 ManyToManyField的關聯對象欄位,它們的作用稍有不同。
訪問外鍵(Foreign Key)值
當你獲取一個ForeignKey 欄位時,你會得到相關的數據模型對象。 例如:
>>> b = Book.objects.get(id=50)
>>> b.publisher
<Publisher: Apress Publishing>
>>> b.publisher.website
② 希望介紹個學python的好網站或者下載資源,或者書本。採納後追加~!謝謝分享
網路雲課堂
http://study.163.com/,裡面有很多不光是python的學習。
比如你找到這個地址中就有python的模塊。
http://study.163.com/find.htm#/find/courselist?ct=31001&ct2=31013
③ 如何閱讀一本書How to read a book.pdf
How to Read a Book, originally published in 1940, has become a rare phenomenon, a living classic. It is the best and most successful guide to reading comprehension for the general reader. And now it has been completely rewritten and updated.
You are told about the various levels of reading and how to achieve them — from elementary reading, through systematic skimming and inspectional reading, to speed reading, you learn how to pigeonhole a book, X-ray it, extract the author's message, criticize. You are taught the different reading techniques for reading practical books, imaginative literature, plays, poetry, history, science and mathematics, philosophy and social science.
Finally, the authors offer a recommended reading list and supply reading tests whereby you can measure your own progress in reading skills, comprehension and speed.
There are over 190,000 copies in print of this classic guide to getting the most from your reading.
④ 《DjangoByExample》pdf下載在線閱讀,求百度網盤雲資源
《Django By Example》(Antonio Mele)電子書網盤下載免費在線閱讀
資源鏈接:
鏈接:https://pan..com/s/1kQe_Jj9b55RbKRPaaIsB_g
書名:Django By Example
作者:Antonio Mele
豆瓣評分:9.3
出版社:Packt Publishing
出版年份:2015-11-30
頁數:474
內容簡介:
Learn Django by building four fully-functional, real-world web applications from scratch
Develop powerful web applications quickly using the best coding practices
Integrate other technologies into your application with clear, step-by-step explanations and comprehensive example code
作者簡介:
Antonio Mele holds an MSc in Computer Science. He has been developing Django projects since 2006 and leads the django.es Spanish Django community. He has founded Zenx IT, a technology company that creates web applications for clients of several instries. Antonio has also worked as a CTO for several technology-based start-ups. His father inspired his passion for computers and programming.
⑤ django新手...如何吧一個view裡面的列表變數傳到另外一個view裡面去
我們看這里
url(r'^(?P<query_result>[.*])/query_book_result/$', views.query_book_result, name='query_book_result'),
這里是捕獲url里的參數,url本身是當做字元串來處理的,那麼捕獲的進來的參數,無疑一定是字元串
你可以稍作嘗試,在query_book_result函數中加一行
ifisinstance(query_result,str):query_result='query_resultisstringhere.'
用來驗證
這里可以稍微處理一下,把字元串變成列表:
query_result =query_result.replace('[','').replace(']','').split(',')
但是實際上列表裡的內容依然是字元串,不是key value的形式,但是單就輸出來講,循環輸出是沒問題了
⑥ 我有一點點Python的基本知識(非常基本) ,想學一下Django, 請推薦幾本入門的Django教程,謝謝
Django 基礎
1. 視頻
推薦使用慕課網的兩門免費在線視頻課程作為入門:
django初體檢
django入門與實踐
這兩門課基本涵蓋了 Django 最核心、同時也是最常用的部分,他們會給你建立一個 Django 的整體概念,便於消除你對 Django 的陌生感和恐懼感。
如果想進一步詳細的了解 Django,有個綜合性的教程名叫
《Django 企業開發實戰》
該教程包含 gibbook 電子書(免費)以及視頻部分(收費)。
其他中文資料
自強學堂:Django 教程 內容詳實免費。值得一提的是作者使用 Django 建站,完全是在實踐 Django 的使用,而且作者從2015年至今一直在根據 Django 版本升級而更新教學內容,從最初的 Django 1.6 更新到了 Django 1.10。作者稱最新版本的 Django 1.11 內容馬上就要推出。
Django Girls 教程 Django Girls 的中文版,使用 Django 1.8。
追夢人物的博客 以 Django 1.10 為基礎開發博客到部署的完整教程。
2. 書籍
Two Scoops of Django:目前有兩個版本 Two Scoops of Django: Best Practices for Django 1.11 和 Two Scoops of Django: Best Practices for Django 1.8 。這本書在 Django 的名氣也是非常大,基本可以說影響過大多數 Django 開發人員,如果要進階稱為 Django 專業開發者,這本書是繞不過去的必看書籍。內容主要涵蓋 Django 的最佳實踐。
Django By Example 在進階的課程中,本書算是不錯的。雖然一些章節(比如第7章)部分代碼仍然存在 bug,但是一方面作者正在該書主頁不斷進行代碼更正,另一方面也是對中國讀者最好的是,這本書已經由同在簡書的 @夜夜月 進行了全書翻譯:《Django By Example》中文版。
Django Unleashed 內容覆蓋較廣,很多內容在其他書籍中並沒有提及,比如密碼的hash與加密等。但是沒有實戰項目。
《Python Web 測試驅動方法》 雖然測試驅動的開發方法(Test-Driven Development,TDD)並不是每個項目都會採用,但是測試的思想與方法還是值得去掌握。Python 作為一門動態語言,沒有靜態類型檢測的情況下,測試的重要性就顯得尤為重要。本書使用 Django 的整個開發流程作為實例,作者不僅講了開發過程單元測試和 Selenium 測試,同時也把部署的內容也覆蓋到。內容始於 Django,但不僅僅是 Django,相信使用其他框架的 Python 開發者也可以從中獲益匪淺。
⑦ Django不能添加應用 在INSTALLED_APPS中不能添加應用(如mysite.books,Django book里的例子)
那個例子版本已經不適合你現在的django版本了。。
⑧ 《TheKubernetesBook》pdf下載在線閱讀,求百度網盤雲資源
《《Kubernetes Book》》(奈傑爾·波爾頓)電子書網盤下載免費在線閱讀
資源鏈接:
鏈接:https://pan..com/s/1XyUxdePh3lMfjY51EkblXw
書名:《Kubernetes Book》
作者:奈傑爾·波爾頓
豆瓣評分:8.0
出版社:獨立出版
頁數:108
內容簡介:
容器在這里,抵抗是徒勞的!現在人們開始了解 Docker,他們需要一個編排平台來幫助他們管理容器化應用程序。Kubernetes 已成為世界上最熱門、最重要的容器編排平台之一。這本書讓你快速上手!
作者簡介:
Nigel is a self confessed technology addict hell-bent on creating the best Docker and container learning resources on the planet. He is the author of over 16 video training courses at www.pluralsight.com, with more than 6 of them on Docker and cloud technologies. He also wrote the book on Data Storage Networking (a well written witty book on one of the most boring subjects on the planet). He lives in the UK and supports a terrible soccer team, but lives it large in the container ecosystem. He also co-hosts the weekly In Tech We Trust podcast.
⑨ [django]from ...import和import的區別
1、from xxx import *會導入xxx.__all__中的所有元素2、from xxx import yyy將xxx.yyy導入到當前執行環境,可以直接使用yyy3、import xxx.yyy將xxx.yyy導入到當前環境,但不能直接使用yyy,必須使用xxx.yyy4、不建議使用from xxx import yyy是因為yyy被直接導入當前環境,可以直接使用yyy,可能其他模塊也有yyy,會重名,導致因命名空間(包空間)混亂而出錯5、特別不建議使用from xxx import *