<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                第二章 應用模式 ---------------------- 本章,我們將學習以下內容: * 獲取請求 * 創建一個概念文檔 * 如何將一個項目分為多個app * 是重新寫一個新的app還是使用已有的 * 開始一個項目之前的最佳實踐 * 為什是Python3? * 啟動SuperBook項目 很多的開發新手從依照正確方法來寫代碼開始,完成一個新的項目。而更多的人經常被引到錯誤的假想,未被使用的功能,并且浪費掉很多時間。花些時間在你的客戶身上,來理解一個項目中的核心請求事件,即使很短的時間也能產生驚人的效果。管理請求是一個值得學習的關鍵知識點。 ## 如何獲取請求 `創新不關乎肯定一切,而是關乎對所有重要的特性說不 ---Steve Jobs` 我通過與客戶耗去數天來仔細地的傾聽他們的需求,以及合理的期望值,拯救了好幾個注定失敗的項目。除了紙(或者他們的數字設備)和一支筆之外什么也沒用,處理過程極其簡單但是卻很有效。這里是一些獲取請求的關鍵地方: 1. 直接和應用的所有者溝通即使他們沒有技術背景。 2. 確保你完整的傾聽他們的需求并提醒他們。 3. 不要使用“模型”這一類的技術術語。保證用語簡單,使用終端用戶能理解的術語比如“用戶賬戶”。 4.合理的期望值。如果某件事情在技術行不可行,或者很難實現,要保證你以正確的方法告知他們。 5.描述的盡可能具象。在大自然中人類是依靠視覺。網站更是如此。使用粗線條和圖形表。不需要多么的完美。 6.分解處理流程,比如用戶注冊。任何多步驟的功能都需要以用箭頭連接的方框畫出。 7.最后,解決用戶敘述表格中的特性, 8.扮演一個活動的角色 9.在融合新特性上要非常,非常地保守。 10.開會,和大家分享你的筆記以避免誤解。 第一個會議會比較長(可能是一整個工作日,或者好幾個小時)。之后,當這些會議的溝通變的順暢時,你可以將它們削減到30分鐘或者一個小時。 所有的這一切的結果會是寫了滿滿的一整頁,以及好幾張的亂糟糟的草圖。 在本書,我們已經著手建構我們自己的一個為超級英雄而構建的稱做SuperBook的社會網絡。A simple sketch based off our discussions with a bunch of randomly selected superheroes is shown as follows: ?????? ![2015-05-28 14 27 35](https://cloud.githubusercontent.com/assets/10941075/7853834/d6eb7c44-0545-11e5-9ae0-8024411bfaed.png) *按照響應式設計的SuperBook網站草圖。桌面(左邊)和手機(右邊)的效果如上.* ## 你是一個會講故事的人嗎? 那么這一章寫的是什么呢?這是一個解釋使用這個網站是做何感覺的簡易文檔。 >### 注釋 >**SuperBook**的概念 下面的訪問記錄是在未來我們的網站SuperBook運營之后所做的整理。 >#### 注釋 >**SuperBook的理念** >下面的是采訪是在未來我們的網站SuperBook網站運行起來之后的記錄。一個半小時的用戶測試在采訪之前就做過了。 >**請你作下自我介紹** 俺叫阿克蘇。俺是一個生活在紐市中心的灰松鼠。不過呢,大家都叫俺阿康。俺爹叫緹巴厘是一個嘻哈音樂明星,他過去也這樣叫俺。俺猜啊,俺從來在唱歌方面就差好多,因此沒能夠子承父業。 >實際哩,在俺很小的時候,俺就有點兒喜歡偷東西。醫生說俺對堅果過敏,這也是大家伙都知道嘀。俺家其他的幾個哥哥吃堅果都沒啥事兒。俺幾個兄弟都可以在任何地方活下去。俺也曾酒館,電影院,游樂園,還有好多地方把歌唱。俺看唱片的時候,忒別認真。 >**好吧,阿康。你為什么被挑選為測試用戶,你知道為什么嗎?** >可能吧,因為俺是紐約大明星里最少知道超級英雄的人。俺猜啊,這人類啊都笑話俺這只可以用蘋果電腦的松鼠。補充一句,俺可是一只非常有耐心的松鼠。 >**就你所見到的,你來說一說你所認識的SuperBook是個什么樣子** >Actually, in my early days, I was a bit of a kleptomaniac. I am allergic to nuts, you know. Other bros have it easy. They can just live off any park. I had to improvise—cafes, movie halls, amusement parks, and so on. I read labels very carefully too. >*Ok, Acorn. Why do you think you were chosen for the user testing? * >Probably, because I was featured in a ?Y ?tar special on lesser?known superheroes. I guess people find it a?using that a squirrel can use a MacBook (Interviewer: this interview was conducted over chat). Plus, I have the attention span of a squirrel. >*Based on what you saw, what is your opinion about SuperBook? * >I think it is a fantastic idea. I mean, people see superheroes all the time. However, nobody cares about them. Most are lonely and antisocial. SuperBook could change that. >*What do you think is different about Superbook?* >It is built from the ground up for people like us. I mean, there is no "Work and Education" nonsense when you want to use your secret identity. Though I don't have one, I can understand why one would. >*Could you tell us briefly some of the features you noticed?* >Sure, I think this is a pretty decent social network, where you can: ``` ? Sign up with any user name (no more, "enter your real name", silliness) ? Fans can follow people without having to add them as "friends" ? Make posts, comment on them, and re-share them ? Send a private post to another user ``` >E?verything is easy. It doesn't take a superhu?an effort to figure it out. Thanks for your time, Acorn. ## 為HTML版面設計 在構建web應用的前幾天,像Photoshop和Flash這樣的工具做到像素級別的模型效果使用是非常廣泛的。 They are hardly recommended or used anymore. 現在對智能手機、平板、筆記本電腦和其他的平臺保持原生和體驗一致比像素層面的效果更為重要了。實際上,大多數的web設計者都基于HTML構建布局。 Creating an HTML mockup is a lot faster and easier than before. If your web designer is unavailable, developers can use a CSS framework such as Bootstrap or ZURB Foundation framework to create pretty decent mockups. 構建一個HTML版本相比以前快了很多。如果你暫時還沒找到Web設計,那么開發者可以利用Bootstrap或者ZRUB這樣的基本的CSS框架來構建非常漂亮的版面。 The goal of creating a mockup is to create a realistic preview of the website. It should not ?erely focus on details and polish to look closer to the final product compared to a sketch, but add interactivity as well. Make your static HTML come to life with working links and some simple JavaScript-driven interactivity. 構建版面的目的就是為了創建一個實際上可用網站的預覽。 A good mockup can give 80 percent of customer experience with less than 20 percent of the overall development effort. 一個好的版面可以達到百分之八十的客戶體驗,以及少于百分之二十的總的開發成本。 ## 設計應用 當你對于自己所要構建的東西有相當好的構思時,你可以開始思考如何使用Django來實現它。再者,這可以誘導人開始編程。然而,當你花了幾分鐘時間來思考設計時,你可以發現非常多的不同方法來解決一個設計問題。 一如測試驅動的開發方法論中提倡的那樣,你也可以首先從測試開始。我們會在測試章節見到更多的TDD方法。我們會在測試那章見到更多的TDD方法。 Whichever approach you take, it is best to stop and think—"Which are the different ways in which I can i?ple?ent this? What are the trade?offs? Which factors are ?ore i?portant in our context? Finally, which approach is the best?? 不亂你選擇的方式是哪一種,最好是停下來想一想——“” Experienced Django developers look at the overall project in different ways. ?ticking to the DRY principle ?or so?eti?es because they get la?y?, they think ??Have I seen this functionality before? For instance, can this social login feature be implemented using a third-party package such as django-all-auth?? If they have to write the app themselves, they start thinking of various design patterns in the hope of an elegant design. However, they first need to break down a project at the top level into apps。 ### 將一個項目分離為多個應用 Django的應用稱做**project**。一個項目由多個應用或者**apps**組成。應用是一組擁有特定功能的Python包。 理論上說,每個app都必須是可以重復使用的。你可以按照自己的需要創建盡可能多的app。絕對不要害怕添加跟多的app,或者重構一個已經存在的應用到多個app。一個典型的Djanog項目包含15到20個app。 到了這一步,一個重要的決定就是是否使用Django的第三方應用,還是從零編寫一個。第三方應用是無需你自己開發,便可以開箱即用的。大多數的包都可以很快安裝并完成配置,幾分鐘之后就能夠使用它們。 換句話來說,編寫自己的應用意味著要常常自己設計并實現模型,視圖,測試。Django和其他類型的應用并沒有區別。 ### 用自己寫的,還是使用別人的 One of Django's biggest strengths is the huge ecosystem of third-party apps. At the time of writing, djangopackages.com lists ?ore than ?,??? packages. You ?ight find that your co?pany or personal library has even ?ore. ?nce your project is broken into apps and you know which kind of apps you need, you will need to take a call for each app—whether to write or reuse an existing one. It might sound easier to install and use a readily available app. However, it not as simple as it sounds. Let's take a look at some third-party authentication apps for our project, and list the reasons why we didn't use them for SuperBook at the time of writing: ``` ? Over-engineered for our needs: We felt that python-social-auth with support for any social login was unnecessary ? Too specific: Using django-facebook would mean tying our authentication to that provided by a specific website ? Python dependencies: One of the requirements of django-allauth is python-openid, which is not actively maintained or unapproved ? Non-Python dependencies: Some packages might have non-Python dependencies, such as Redis or Node.js, which have deployment overheads ? Not reusable: Many of our own apps were not used because they were not very easy to reuse or were not written to be reusable ``` None of these packages are bad. They just don't meet our needs for now. They might be useful for a different project. In our case, the built-in Django auth app was good enough. On the other hand, you might prefer to use a third-party app for some of the following reasons: ``` ? Too hard to get right? Do your ?odel's instances need to for? a tree? Use django-mptt for a database?efficient i?ple?entation ? Best or recommended app for the job: This changes over time but packages such as django-redis are the most recommended for their use case ? Missing batteries: Many feel that packages such as django-model-utils and django-extensions should have been part of the framework ? Minimal dependencies: This is always good in my book ``` S?o, should you reuse apps and save ti?e or write a new custo? app? I would recommend that you try a third-party app in a sandbox. If you are an intermediate Django developer, then the next section will tell you how to try packages in a sandbox. ? #### 我的app沙箱 From time to time, you will come across several blog posts listing the "must-have Django packages". However, the best way to decide whether a package is appropriate for your project is Prototyping. Even if you have created a Python virtual environment for development, trying all these packages and later discarding them can litter your environment. So, I usually end up creating a separate virtual environment named "sandbox" purely for trying such apps. Then, I build a small project to understand how easy it is to use. Later, if I am happy with my test drive of the app, I create a branch in my project using a version control tool such as Git to integrate the app. Then, I continue with coding and running tests in the branch until the necessary features are added. Finally, this branch will be reviewed and merged back to the mainline (sometimes called master) branch. ### 它是由哪個包組成的? 為了闡明過程,我們的SuperBook項目可以粗略地分解為下列app(沒有全部列出): **Authentication**(內建django.auth): 這個app處理用戶注冊,登錄,和登出。 **Accounts**(定制): 這個app提偶那個額外的用戶賬戶信息。 **Posts**(定制): 這個app提供發表和回復功能 **Pows**(定制): 這個app跟蹤有多少“碰”(支持或者喜歡) **Boostrap forms**(crispy-forms): 這個app處理表單布局和風格 這里,一個app已經被標記為從零(標記為“定制”)構建,或者我們要使用的第三方Django應用。隨著,項目的發展,這些選項或許改變。不過,這對一個新手足夠了。 ## 在開始項目之前 While preparing a development environment, make sure that you have the following in place: ``` ? A fresh Python virtual environment: Python 3 includes the venv module or you can install virtualenv. Both of them prevent polluting your global Python library. ? Version control: Always use a version control tool such as Git or Mercurial. They are life savers. You can also ?ake changes ?uch ?ore confidently and fearlessly. ? Choose a project template: Django's default project template is not the only option. Based on your needs try others such as twoscoops (https://github.com/twoscoops/django-twoscoops-project) or edge (https://github.com/arocks/edge). ? Deployment pipeline: I usually worry about this a bit later, but having an easy deployment process helps to show early progress. I prefer Fabric or Ansible. ``` ## SuperBook-少年來吧,接受你的任務 This book believes in a practical and pragmatic approach of demonstrating Django design patterns and the best practices through examples. For consistency, all our examples will be about building a social network project called SuperBook. SuperBook focusses exclusively on the niche and often neglected market segment of people with exceptional super powers. You are one of the developers in a tea? comprised of other developers, web designers, a marketing manager, and a project manager. The project will be built in the latest version of Python (Version 3.4) and Django (Version 1.7) at the time of writing. Since the choice of Python 3 can be a contentious topic, it deserves a fuller explanation. ### 為什么選Python 3? While the development of Python ? started in ????, its first release, Python ?.?, was released on December 3, 2008. The main reasons for a backward incompatible version were—switching to Unicode for all strings, increased use of iterators, cleanup of deprecated features such as old-style classes, and some new syntactic additions such as the nonlocal statement. The reaction to Python 3 in the Django community was rather mixed. Even though the language changes between Version 2 and 3 were small (and over time, reduced), porting the entire Django codebase was a significant ?igration effort. ?n February ??, Django ?.? beca?e the first version to support Python ?. Developers have clarified that, in future, Django will be written for Python ? with an ai? to be backward compatible to Python 2. For this book, Python 3 was ideal for the following reasons: 就本書來說,Python 3 由于以下幾個原因看來它是最理想的: ? Better syntax? This fixes a lot of ugly syntaxes, such as izip, xrange, and __unicode__, with the cleaner and more straightforward zip, range, and `__str__`. ? Sufficient third-party support: Of the top 200 third-party libraries, more than 80 percent have Python 3 support. ? No legacy code: We are creating a new project, rather than dealing with legacy code that needs to support an older version. 不存在遺留的代碼:我們創建一個新的項目,而不是來處理需要支持舊版本代碼。 ? Default in modern platforms: This is already the default Python interpreter in Arch Linux. Ubuntu and Fedora plan to complete the switch in a future release. ? It is easy: From a Django development point of view, there are very few changes, and they can all be learnt in a few minutes. 使用方便:站在Django開發的觀點來看,其改變非常微小,所有變更的地方學起來也很快。 The last point is important. Even if you are using Python 2, this book will serve you fine. Read a?ppendix ? to understand the changes. You will need to make only minimal adjustments to backport the example code. 最后一點很重要。即使你現在使用的是Python 2,本書中的例子也能夠很好的運行。 ### 開始項目 本節是SuperBook項目的安裝說明,它包含在本書中使用的所有代碼實例。要為最新的安裝注釋檢查項目的README文件。推薦你創建一個新的目錄,superbook,首先包含虛擬環境,項目源碼。 Ideally, every Django project should be in its own separate virtual environment. This makes it easy to install, update, and delete packages without affecting other applications. In Python 3.4, using the built-in venv module is recommended since it also installs pip by default: 理論上,每一個Django項目都應該有自己的虛擬環境。使用虛擬環境可以讓Django的安裝,升級顯得很輕松,而且刪除包也不會影響到其他的應用。在Python 3.4中,建議使用內建的venv模塊,因為它默認也安裝了pip: ```python $ python3 -m venv sbenv $ source sbenv/bin/activate $ export PATH="`pwd`/sbenv/local/bin:$PATH" ``` These commands should work in most Unix-based operating systems. For installation instructions on other operating systems or detailed steps please refer to the README file at the ?ithub repository? https://github.com/DjangoPatternsBook/ superbook. In the first line, we are invoking the Python ?.? executable as python3; do confir? if this is correct for your operating syste? and distribution. 這些命令可以運行在大多數的基于Unix的操作系統。例如 The last export command might not be required in some cases. If running pip freeze lists your system packages rather than being empty, then you will need to enter this line. 代碼中位于最后`export`命令在某些情況下不是必須的。如果運行`pip freeze`列出的系統包是空的,那么你需要輸入這一行。 >#### 提示 開始Django項目之前,創建一個新的虛擬環境 接下來,從GitHub克隆項目例子,并安裝依賴: ```python $ git clone https://github.com/DjangoPatternsBook/superbook.git $ cd superbook $ pip install -r requirements.txt ``` 如果你想看一看已完成的SuperBook網站,只要運行migrate并啟動測試服務器就行了: ```python $ cd final $ python manage.py migrate $ python manage.py createsuperuser $ python manage.py runserver ``` In Django 1.7, the migrate command has superseded the syncdb command. We also need to explicitly invoke the createsuperuser command to create a super user so that we can access the admin. 在Django1.7中,migrate命令已經取代了syncdb命令。我們也需要明確地調用creteasuperuser命令來創建一個超級用戶,這樣我們就可以訪問admin了。 You can navigate to http://127.0.0.1:8000 or the URL indicated in your terminal and feel free to play around with the site. 你可以瀏覽`http://127.0.0.1:8000`或者在終端指明URL,隨便玩玩這個網站。 ## 總結 Beginners often underestimate the importance of a good requirements-gathering process. At the same time, it is important not to get bogged down with the details, because programming is inherently an exploratory process. The most successful projects spend the right amount of time preparing and planning before development so that it yields the maximum benefits. 新手總是低估了一個優質的`請求-獲取`流程的重要性。于此同時,重要的是不要被細節所束縛,因為從本質來說,編程就是一個探索的過程。很多成功的項目在開發之前都花掉了大量的時間來準備和計劃,這樣才能獲得最佳效果。 We discussed many aspects of designing an application, such as creating interactive mockups or dividing it into reusable components called apps. We also discussed the steps to set up SuperBook, our example project. 我談論了設計應用的很多方面,比如創建交互模型,或者是將它分割到多個稱為app的可重復使用組件。同時我們也討論了配置項目SuperBook的步驟。 In the next chapter, we will take a look at each component of Django in detail and learn the design patterns and best practices around them. 在下一章,我們會詳細地瀏覽Django的每個組件,并學習與這些組件相關的最佳實踐。 -------------------- ? Creative Commons BY-NC-ND 3.0 | [我要訂閱](https://github.com/cundi/Django-Design-Patterns-and-Best-Practices/subscription) | [我要捐助](https://github.com/cundi/Web.Development.with.Django.Cookbook/issues/3)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看