《Django by Example》中文版

Total Page:16

File Type:pdf, Size:1020Kb

《Django by Example》中文版 1 / 294 《Django By Example》中文版 目录 ...................................................................................................................................................................................................... 1 《Django By Example》中文版 ............................................................................................................................................. 2 第一章 创建一个 blog 应用 ....................................................................................................................................................... 8 安装 Django ......................................................................................................................................................................... 8 创建一个独立的 Python 环境 ............................................................................................................................................ 8 使用 pip 安装 Django ......................................................................................................................................................... 9 创建你的第一个项目 .......................................................................................................................................................... 9 运行开发服务器 ................................................................................................................................................................ 10 项目设置 ............................................................................................................................................................................ 11 项目和应用 ........................................................................................................................................................................ 12 创建一个应用 .................................................................................................................................................................... 12 设计 blog 数据架构 ........................................................................................................................................................... 12 激活你的应用 .................................................................................................................................................................... 14 创建和进行数据库迁移 .................................................................................................................................................... 14 为你的模型(models)创建一个管理站点 .................................................................................................................... 15 创建一个超级用户 ............................................................................................................................................................ 15 Django 管理站点 ............................................................................................................................................................... 16 在管理站点中添加你的模型(models) ........................................................................................................................ 16 定制 models 的展示形式 .................................................................................................................................................. 17 使用查询集(QuerySet)和管理器(managers)........................................................................................................ 18 创建对象 ............................................................................................................................................................................ 19 更新对象 ............................................................................................................................................................................ 19 取回对象 ............................................................................................................................................................................ 20 使用 filter()方法 ................................................................................................................................................................ 20 使用 exclude() .................................................................................................................................................................... 20 使用 order_by() ................................................................................................................................................................. 20 删除对象 ............................................................................................................................................................................ 21 查询集(QuerySet)什么时候会执行 ............................................................................................................................ 21 创建 model manager ......................................................................................................................................................... 21 构建列和详情视图(views) ........................................................................................................................................... 21 创建列和详情 views .......................................................................................................................................................... 22 为你的视图(views)添加 URL 模式 ............................................................................................................................. 22 模型(models)的标准 URLs ......................................................................................................................................... 23 为你的视图(views)创建模板(templates) ............................................................................................................... 24 添加页码 ............................................................................................................................................................................ 26 使用基于类的视图(views) ........................................................................................................................................... 28 总结 ............................................................................................................................................................................................ 28 译者总结 ............................................................................................................................................................................ 29 第二章 用高级特性来增强你的 blog ...................................................................................................................................... 29 通过 email 分享帖子 ................................................................................................................................................. 29 使用 Django 创建表单 .............................................................................................................................................. 29 在视图(views)中操作表单 ................................................................................................................................... 30 使用 Django 发送 email.................................................................................................................................................... 31 在模板(templates)中渲染表单 .................................................................................................................................... 32 2 / 294 创建一个评论系统 ............................................................................................................................................................ 35 通过模型(models)创建表单 ........................................................................................................................................ 36 在视图(views)中操作 ModelForms ............................................................................................................................. 36 在帖子详情模板(template)中添加评论 ..................................................................................................................... 38 增加标签(tagging)功能 ................................................................................................................................................ 40 检索类似的帖子 ................................................................................................................................................................ 44 总结 .................................................................................................................................................................................... 45 第三章 扩展你的 blog 应用 .................................................................................................................................................... 46 创建自定义的模板标签(template tags)和过滤器(filters) ........................................................................... 46 创建自定义的模板标签(template tags) ........................................................................................................... 46 创建自定义的模板过滤器(template filters) .................................................................................................... 50 为你的站点添加一个站点地图(sitemap) ......................................................................................................... 51 为你的 blog 帖子创建 feeds .................................................................................................................................. 54 使用 Solr 和 Haystack 添加一个搜索引擎 ........................................................................................................... 55 安装 Solr ..................................................................................................................................................................
Recommended publications
  • CRITICAL THEORY and AUTHORITARIAN POPULISM Critical Theory and Authoritarian Populism
    CDSMS EDITED BY JEREMIAH MORELOCK CRITICAL THEORY AND AUTHORITARIAN POPULISM Critical Theory and Authoritarian Populism edited by Jeremiah Morelock Critical, Digital and Social Media Studies Series Editor: Christian Fuchs The peer-reviewed book series edited by Christian Fuchs publishes books that critically study the role of the internet and digital and social media in society. Titles analyse how power structures, digital capitalism, ideology and social struggles shape and are shaped by digital and social media. They use and develop critical theory discussing the political relevance and implications of studied topics. The series is a theoretical forum for in- ternet and social media research for books using methods and theories that challenge digital positivism; it also seeks to explore digital media ethics grounded in critical social theories and philosophy. Editorial Board Thomas Allmer, Mark Andrejevic, Miriyam Aouragh, Charles Brown, Eran Fisher, Peter Goodwin, Jonathan Hardy, Kylie Jarrett, Anastasia Kavada, Maria Michalis, Stefania Milan, Vincent Mosco, Jack Qiu, Jernej Amon Prodnik, Marisol Sandoval, Se- bastian Sevignani, Pieter Verdegem Published Critical Theory of Communication: New Readings of Lukács, Adorno, Marcuse, Honneth and Habermas in the Age of the Internet Christian Fuchs https://doi.org/10.16997/book1 Knowledge in the Age of Digital Capitalism: An Introduction to Cognitive Materialism Mariano Zukerfeld https://doi.org/10.16997/book3 Politicizing Digital Space: Theory, the Internet, and Renewing Democracy Trevor Garrison Smith https://doi.org/10.16997/book5 Capital, State, Empire: The New American Way of Digital Warfare Scott Timcke https://doi.org/10.16997/book6 The Spectacle 2.0: Reading Debord in the Context of Digital Capitalism Edited by Marco Briziarelli and Emiliana Armano https://doi.org/10.16997/book11 The Big Data Agenda: Data Ethics and Critical Data Studies Annika Richterich https://doi.org/10.16997/book14 Social Capital Online: Alienation and Accumulation Kane X.
    [Show full text]
  • Social Media Consumer Engagement: a Study on the Most Popular Fashion Brands’ Fan Pages
    Department of Business and Management Master Thesis in Marketing Management Social Media Consumer Engagement: a Study on the Most Popular Fashion Brands’ Fan Pages. SUPERVISOR: CANDIDATE: Prof. Peter Leeflang Angelo Lombardi ID 632721 CO‐SUPERVISOR: Prof. Simona Romani Academic year 2011‐2012 Social Media Consumer Engagement: a Study on the Most Popular Fashion Brands’ Fan Pages. 2 Table of contents Introduction............................................................................................................... 5 Chapter 1 - Social Media.......................................................................................... 7 1.1 The evolution of Media and Internet ........................................................................ 7 1.2 Web 2.0......................................................................................................................... 9 1.3 What is Social Media? .............................................................................................. 12 1.4 User Generated Content (UGC) .............................................................................. 15 1.5 Classification of social media ................................................................................... 18 1.5.1 Collaborative projects.......................................................................................... 22 1.5.2 Blogs.................................................................................................................... 23 1.5.3 Content communities..........................................................................................
    [Show full text]
  • CARL ZIMMER Author & Journalist
    CARL ZIMMER Author & journalist carlzimmer.com @carlzimmer BIOGRAPHY The New York Times Book Review calls Carl Zimmer "as fine a science essayist as we have." He is the author of thirteen acclaimed books and a columnist for the New York Times. Zimmer first be- gan writing about science at Discover, where he served for five years as a senior editor, and has gone on to write hundreds of features for magazines including The Atlantic, The New York Times Magazine, Time, National Geographic, and Scientific American. He has also served as a scientific editor for television documentaries, consulted on museum exhibits, and contributed his writing to major science web sites. Zimmer has earned numerous honors for his work. In 2007 he won the National Academies Communication Award, and he has won the American Association for the Advancement of Sci- ences Science Journalism Award three times. In 2015, Zimmer won the Distinguished Service Award from the National Association of Biology Teachers, and in 2016, he won the Stephen Jay Gould Prize, awarded by the Society for the Study of Evolution. In 2018, Zimmer’s book She Has Her Mother’s Laugh was named by Publisher’s Weekly one of the ten best books of the year. The Guardian named it the best science book of 2018 and The New York Times Book Review chose it as a Notable Book of the Year. It was short-listed for the Baillie-Gifford Prize for Nonfiction and a fi- nalist for the PEN/E.O. Wilson Literary Science Writing Prize. His articles have been antholo- gized in both The Best American Science and Nature Writing series and The Best American Science Writing series.
    [Show full text]
  • Acquiring Customers Through Blogs and Twitter Objectives
    Chapter 6 Acquiring customers through Blogs and Twitter Objectives • After going through this chapter, you will be able to understand: – How to use Blogs and Twitter for marketing – Advantages of using micro blogging – Discuss the process of leveraging Twitter to enhance business growth Introduction • A blog is a discussion or informational site published on the World Wide Web and consisting of discrete entries typically displayed in reverse chronological order • The rise of Twitter and other "microblogging" systems helps integrate MABs and single-author blogs into societal new streams. • Blog can also be used as a verb, meaning to maintain or add content to a blog. Introduction • A majority of blogs are interactive; allowing visitors to leave comments and even message each other via GUI widgets on the blogs, and it is this interactivity that distinguishes them from other static websites. • A typical blog combines text, images, and links to other blogs, Web pages, and other media related to its topic. Background and history • The term "weblog" was coined by Jorn Barger on 17 December 1997. • The short form, "blog", was coined by Peter Merholz, who jokingly broke the word weblog into the phrase we blog in the sidebar of his blog Peterme.com in April or May 1999. • Shortly thereafter, Evan Williams at Pyra Labs used "blog" as both a noun and verb and devised the term "blogger" in connection with Pyra Labs' Blogger product, leading to the popularization of the terms. Background and history • Origins – Before blogging became popular, digital communities took many forms, including Usenet, commercial online services such as GEnie, BiX and the early CompuServe, e- mail lists and Bulletin Board Systems (BBS).
    [Show full text]
  • Introduction
    MERLOT Journal of Online Learning and Teaching Vol. 5, No. 2, June 2009 Integrating Online Multimedia into College Course and Classroom: With Application to the Social Sciences Michael V. Miller Department of Sociology The University of Texas at San Antonio San Antonio, TX 78249 USA [email protected] Abstract Description centers on an approach for efficiently incorporating online media resources into course and classroom. Consideration is given to pedagogical rationale, types of media, locating programs and clips, content retrieval and delivery, copyright issues, and typical problems experienced by instructors and students using online resources. In addition, selected media-relevant websites appropriate to the social sciences along with samples of digital materials gleaned from these sites are listed and discussed. Keywords: video, audio, media, syllabus, documentaries, Internet, YouTube, PBS Introduction Multimedia resources can markedly augment learning content by virtue of generating vivid and complex mental imagery. Indeed, instruction dependent on voice lecture and reading assignments alone often produces an overly abstract treatment of subject matter, making course concepts difficult to understand, especially for those most inclined toward concrete thinking. Multimedia can provide compelling, tangible applications that help breakdown classroom walls and expose students to the external world. It can also enhance learning comprehension by employing mixes of sights and sounds that appeal to variable learning styles and preferences. Quality materials, in all, can help enliven a class by making subject matter more relevant, experiential, and ultimately, more intellectually accessible. Until recently, nonetheless, film and other forms of media were difficult to exploit. They had to be located, ordered, and physically procured well in advance either through purchase, library loan, or broadcast dubbing.
    [Show full text]
  • Website, Blog and Portal Website
    Website, blog and portal Website: - The form "website" has become the most common spelling, but "Web site" (capitalised) and "web site" are also widely used, though declining. Some academia, some large book publishers, and some dictionaries still use "Web site", reflecting the origin of the term in the proper name World Wide Web. There has also been similar debate regarding related terms such as web page, web server, and webcam. A website, also written as web site, or simply site, is a set of related web pages1 typically served from a single web domain2. A website is hosted on at least one web server, accessible via a network such as the Internet or a private local area network through an Internet address known as a Uniform resource locator. All publicly accessible websites collectively constitute the World Wide Web. A webpage is a document, typically written in plain text interspersed with formatting instructions of Hypertext Mark-up Language (HTML,XHTML). A webpage may incorporate elements from other websites with suitable mark-up anchors. Webpages are accessed and transported with the Hypertext Transfer Protocol (HTTP), which may optionally employ encryption (HTTP Secure, HTTPS) to provide security and privacy for the user of the webpage content. The user's application, often a web browser, renders the page content according to its HTML mark-up instructions onto a display terminal. The pages of a website can usually be accessed from a simple Uniform Resource Locator (URL) called the web address. The URLs of the pages organize them into a hierarchy, although hyperlinking between them conveys the reader's perceived site structure and guides the reader's navigation of the site which generally includes a home page with most of the links to the site's web content, and a supplementary about, contact and link page.
    [Show full text]
  • OSINT Handbook September 2020
    OPEN SOURCE INTELLIGENCE TOOLS AND RESOURCES HANDBOOK 2020 OPEN SOURCE INTELLIGENCE TOOLS AND RESOURCES HANDBOOK 2020 Aleksandra Bielska Noa Rebecca Kurz, Yves Baumgartner, Vytenis Benetis 2 Foreword I am delighted to share with you the 2020 edition of the OSINT Tools and Resources Handbook. Once again, the Handbook has been revised and updated to reflect the evolution of this discipline, and the many strategic, operational and technical challenges OSINT practitioners have to grapple with. Given the speed of change on the web, some might question the wisdom of pulling together such a resource. What’s wrong with the Top 10 tools, or the Top 100? There are only so many resources one can bookmark after all. Such arguments are not without merit. My fear, however, is that they are also shortsighted. I offer four reasons why. To begin, a shortlist betrays the widening spectrum of OSINT practice. Whereas OSINT was once the preserve of analysts working in national security, it now embraces a growing class of professionals in fields as diverse as journalism, cybersecurity, investment research, crisis management and human rights. A limited toolkit can never satisfy all of these constituencies. Second, a good OSINT practitioner is someone who is comfortable working with different tools, sources and collection strategies. The temptation toward narrow specialisation in OSINT is one that has to be resisted. Why? Because no research task is ever as tidy as the customer’s requirements are likely to suggest. Third, is the inevitable realisation that good tool awareness is equivalent to good source awareness. Indeed, the right tool can determine whether you harvest the right information.
    [Show full text]
  • Redalyc.A PROPOSAL to MANAGE LESSONS LEARNED in PROJECTS
    International Journal of Innovation E-ISSN: 2318-9975 [email protected] Universidade Nove de Julho Brasil Silveira Chaves, Marcirio; Santos Veronese, Giuliana A PROPOSAL TO MANAGE LESSONS LEARNED IN PROJECTS: WEB 2.0 TECHNOLOGIES TO PROMOTE INNOVATION International Journal of Innovation, vol. 2, núm. 1, enero-junio, 2014, pp. 1-17 Universidade Nove de Julho Valdivia, Brasil Available in: http://www.redalyc.org/articulo.oa?id=499150609001 How to cite Complete issue Scientific Information System More information about this article Network of Scientific Journals from Latin America, the Caribbean, Spain and Portugal Journal's homepage in redalyc.org Non-profit academic project, developed under the open access initiative Received on December 05, 2013 / Approved on April 6, 2014 Responsible Editor: Leonel Cesar Rodrigues, Ph.D. Evaluation Process: Double Blind Review E-ISSN: 2318 -9975 PROPOSAL TO MANAGE LESSONS LEARNED IN PROJECTS: WEB 2.0 TECHNOLOGIES TO PROMOTE INNOVATION 1Marcirio Silveira Chaves A 2 Giuliana Santos Veronese ABSTRACT The web 2.0 is transforming the project management in organizations by improving communication and collaboration. The new generation of web-based collaborative tools provides much better experience than the traditional software package allowing document sharing, integrated task tracking, enforcing team processes and agile planning. Despite of the indubitable benefits brought by web 2.0, the use of these technologies to promote knowledge management remains unexplored. For many project managers to obtain and integrate information from different tools of previous similar projects in global organizations remains a challenge. This theoretical paper presents a proposal that suggests an innovation in the knowledge management area applying web 2.0 technologies.
    [Show full text]
  • Foundation Course -7 2017-2018
    Foundation Course -7 2017-2018 COMMUNICATION SKILLS AND SOFT SKILLS-3 (CSS -3) COURSE CONTENT (30 hours) A current axiom is that hard skills will get a person an interview, but soft skills will get that person the job. Unit I of the course is on soft skills, which are absolutely necessary in the global job market. Writing is considered the most difficult of all the skills. Units II to V help the learner improve their writing skills, especially academic/formal writing. Unit I: Soft Skills 1. Positive Attitude 2. Body Language 3. SWOT/SWOC Analysis 4. Emotional Intelligence 5. Netiquette Unit II: Paragraph Writing 1. Paragraph Structure 2. Development of Ideas Unit III: Paraphrasing and Summarizing 3.1. Elements of Effective Paraphrasing 3.2. Techniques for Paraphrasing 3.3 What Makes a Good Summary? 3.4. Stages of Summarizing Unit IV: Letter Writing 4.1. Letter Writing (Formal and Informal) 4.2. E-correspondence Unit V: 5.1Resume and CV 5.2 Cover Letter 1 UNIT-I: SOFT SKILLS 1.1 POSITIVE ATTITUDE A positive attitude makes you happier and more resilient, it improves your relationships, and it even increases your chances of success in any endeavor. In addition, having a positive attitude makes you more creative and it can help you to make better decisions. To top it all off, there are studies that show that people with a positive attitude live longer than their sourpuss counterparts. Below you’ll discover 21 ways to create and maintain a positive attitude. 1. Have a Morning Routine. How you start your morning sets the tone for the rest of the day.
    [Show full text]
  • ~. Ca~~ ~~.: ~,~Z~ ~C~C~S`7 the NEW YORK TIMES COMPANY, JURY TRIAL DEMANDED D/B/A the New York Times, a New York Corporation
    VIRGINIA: IN THE CIRCUIT COURT FOR THE CITY OF LYNCHBURG LIBERTY UNIVERSITY, INC., ) Plai~ztiff, ~. Ca~~ ~~.: ~,~Z~ ~c~C~S`7 THE NEW YORK TIMES COMPANY, JURY TRIAL DEMANDED d/b/a The New York Times, a New York Corporation, ELIZABETH WILLIAMSON, and JULIA RENDLEMAN Defend~r«ts. COMPLAINT COMES NOW, the Plaintiff, Liberty University, Inc. ("Liberty"), by counsel, and files this Complaint against defendants The New York Times Company ("New York Times"), Elizabeth Williamson ("Williamson"), and Julia Rendleman ("Rendleman") (collectively, "defendants" and, each, a "defendant"), and in support thereof states as follows: PRELIMINARY STATEMENT 1. In 2006, the managing editor of the New York Times was asked on national television, "how does it feel to be the managing editor of a paper that makes stuff up?" Fourteen years later, Liberty University has the same question. 2. On March 29, 2020, defendants published an article that intentionally misrepresented that Liberty had "reopened" its campus after spring break and suffered a COVID- 19 outbreak as a result. That message was apparent to every reader from the article's plain language. The online article announced that "Liberty Brings Back its Students, and Coronavirus, Too." The print edition likewise proclaimed that "A University Reopened, and Students Got Sick.'' Both versions stated explicitly that Liberty University "partly reopened] . .Then students started getting sick" including "nearly a dozen Liberty students . sick with symptoms that suggest COVID-19." Defendant New York Times made the same claims in an official tweet about the story: "Jerry Falwell, Jr., president of Liberty University, reopened the school's campus last week.
    [Show full text]
  • CARL ZIMMER LATEST-Web 10-31-14
    CARL ZIMMER [email protected] http://carlzimmer.com BIOGRAPHY The New York Times Book Review calls Carl Zimmer "as fine a science essayist as we have." Zim- mer is the author of thirteen acclaimed books about biology and medicine. He writes a weekly column about science for The New York Times, and is the author of hundreds of features for the New York Times, Time, National Geographic, Scientific American, and many other publications. For a decade Zimmer has written an award-winning blog about biology, “The Loom,” which has been hosted by National Geographic since 2012. Zimmer has served as a scientific editor for televi- sion documentaries, consulted on museum exhibits, and contributed his writing to major sci- ence web sites. A graduate of Yale, Zimmer first began writing about science at Discover, where he served for five years as a senior editor. His work has been anthologized in both The Best American Science and Nature Writing series and The Best American Science Writing series, and he has won fellowships for his books from the John Simon Guggenheim Memorial Foundation and the Alfred P. Sloan Foundation. Zimmer’s articles have earned a number of awards. In 2007 he won the National Academies Communication Award. He has won the American Association for the Advance- ment of Sciences Science Journalism Award three times: in 2009 and 2012 for large-circulation newspapers, and 2004 for online journalism. His book Soul Made Flesh, a history of neurology, was named a notable books of the year by the New York Times Book Review. His 2008 book, Mi- crocosm, was a finalist for the Los Angeles Times Book Prize and was longlisted for the Royal Socie- ty Prize for Science Books.
    [Show full text]
  • The Art of Being Human: a Textbook for Cultural Anthropology
    Kansas State University Libraries New Prairie Press NPP eBooks Monographs 2018 The Art of Being Human: A Textbook for Cultural Anthropology Michael Wesch Kansas State University, [email protected] Follow this and additional works at: https://newprairiepress.org/ebooks Part of the Multicultural Psychology Commons, and the Social and Cultural Anthropology Commons This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 4.0 License. Recommended Citation Wesch, Michael, "The Art of Being Human: A Textbook for Cultural Anthropology" (2018). NPP eBooks. 20. https://newprairiepress.org/ebooks/20 This Book is brought to you for free and open access by the Monographs at New Prairie Press. It has been accepted for inclusion in NPP eBooks by an authorized administrator of New Prairie Press. For more information, please contact [email protected]. student submissions at anth101.com Anthropology is the study of all humans in all times in all places. But it is so much more than that. “Anthropology“ requires strength, valor, and courage,” Nancy Scheper-Hughes noted. “Pierre Bourdieu called anthropology a combat sport, an extreme sport as well as a tough and rigorous discipline. … It teaches students not to be afraid of getting one’s hands dirty, to get down in the dirt, and to commit yourself, body and mind. Susan Sontag called anthropology a “heroic” profession.” WhatW is the payoff for this heroic journey? You will find ideas that can carry you across rivers of doubt and over mountains of fear to find the the light and life of places forgotten. Real anthropology cannot be contained in a book.
    [Show full text]