① 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 *