<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>python3 on Arunrocks</title>
    <link>https://arunrocks.com/tags/python3/</link>
    <description>Recent articles in python3 on Arunrocks</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 30 Jan 2018 06:59:49 +0530</lastBuildDate><atom:link href="https://arunrocks.com/tags/python3/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Django Release Schedule and Python 3</title>
      <link>https://arunrocks.com/django-release-schedule-and-python-3/</link>
      <pubDate>Tue, 30 Jan 2018 06:59:49 +0530</pubDate>
      
      <guid>https://arunrocks.com/django-release-schedule-and-python-3/</guid>
      <description>&lt;p&gt;Do long term releases confuse you? For the longest time I was not sure which version of Ubuntu to download - the latest release or the LTS? I see a number of Django developers confused about Django&amp;rsquo;s releases. So I prepared this handy guide to help you choose (or confuse?).&lt;/p&gt;
&lt;h2 id=&#34;which-version-to-use&#34;&gt;Which Version To Use?&lt;/h2&gt;
&lt;p&gt;Django has now &lt;a href=&#34;https://www.djangoproject.com/weblog/2015/jun/25/roadmap/&#34;&gt;standardized on a release schedule&lt;/a&gt; with three kinds of releases:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Feature Release&lt;/strong&gt;: These releases will have new features or improvements to existing features. It will happen every 8 months and will have 16 months of extended support from release. They have version numbers like A.B (note there&amp;rsquo;s no minor version).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Long-Term Support (LTS) Release&lt;/strong&gt;: These are special kind of feature releases, which have a longer extended support of three years from the release date. These releases will happen every two years. They have version numbers like A.2 (since every third feature release will be a LTS). LTS releases have few months of overlap to aid in a smoother migration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Patch Release&lt;/strong&gt;: These releases are bug fixes or security patches. It is recommended to deploy them as soon as possible. Since they have minimal breaking changes, these upgrades should be painless to apply. They have version numbers like A.B.C&lt;/p&gt;
&lt;p&gt;Django roadmap visualized below should make the release approach clearer:&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/django-releases.png&#34; alt=&#34;Django Releases (LTS and feature releases) explained&#34;   width=1741 height=&#34;1240&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;The dates are indicative and may change. This is not an official diagram but something that I created for my understanding.&lt;/p&gt;
&lt;p&gt;The big takeaway is that Django 1.11 LTS will be the last release to support Python 2 and it is supported until April 2020. Subsequent versions will use only Python 3.&lt;/p&gt;
&lt;p&gt;The right Django version for you will be based on how frequent you can upgrade your Django installation and what features you need. If your project is actively developed and the Django version can be upgraded at least once in 16 months, then you should install the latest feature release regardless of whether it is LTS or non-LTS.&lt;/p&gt;
&lt;p&gt;Otherwise, if your project is only occasionally developed then you should pick the most recent LTS version. Upgrading your project&amp;rsquo;s Django dependency from one feature release to another can be a non-trivial effort. So, read the release notes and plan accordingly.&lt;/p&gt;
&lt;p&gt;In any case, make sure you install Patch Releases as soon as they are released. Now, if you are still on Python 2 then read on.&lt;/p&gt;
&lt;h2 id=&#34;python-3-has-crossed-tipping-point&#34;&gt;Python 3 has crossed tipping point&lt;/h2&gt;
&lt;p&gt;When I decided to use Python 3 only while writing my book &amp;ldquo;Django Design Patterns and Best Practices&amp;rdquo; in 2015, it was a time when Python 2 versus Python 3 was hotly debated. However, to me Python 3 seemed much more cleaner without arcane syntax like class methods named &lt;code&gt;__unicode__&lt;/code&gt;  and classes needing to derive from &lt;code&gt;object&lt;/code&gt; parent class.&lt;/p&gt;
&lt;p&gt;Now, it is quite a different picture. We just saw how Django no longer supports Python 2 except for the last LTS release. This is a big push for many Python shops to consider Python 3.&lt;/p&gt;
&lt;p&gt;Many platforms have upgraded their default Python interpreter. Starting 1st March 2018, Python 3 is announced to be the default &amp;ldquo;python&amp;rdquo; in Homebrew installs. ArchLinux had completely switched to Python 3 since 2010.&lt;/p&gt;
&lt;p&gt;Fedora has switched to Python 3 as its system default since &lt;a href=&#34;https://fedoraproject.org/wiki/Changes/Python_3_as_Default&#34;&gt;version 23&lt;/a&gt;. Even though &lt;code&gt;python&lt;/code&gt; command will launch &lt;code&gt;python3&lt;/code&gt;, the symlink &lt;code&gt;/usr/bin/python&lt;/code&gt; will still point to &lt;code&gt;python2&lt;/code&gt; for backward compatibility. So it is probably a good idea to use &lt;code&gt;#!/usr/bin/env python&lt;/code&gt; idiom in your shell scripts.&lt;/p&gt;
&lt;p&gt;On 26 April 2018, when Ubuntu 18.04 LTS (Bionic Beaver) will be released, it is planned to be have &lt;a href=&#34;https://wiki.ubuntu.com/Python/Python36Transition&#34;&gt;Python 3.6 as default&lt;/a&gt;. Further upstream, the next Debian release in testing - Debian 10 (Buster) &lt;a href=&#34;https://wiki.ubuntu.com/Python/Python36Transition&#34;&gt;is expected to transition to Python 3.6&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Moving to packages, the &lt;a href=&#34;https://python3wos.appspot.com/&#34;&gt;Python 3 Wall of Superpowers&lt;/a&gt; shows that with the backing of 190 out of 200 packages, at the time of writing, we have nearly all popular Python packages on Python 3. The only notable package remaining is supervisor, which is about to turn green in &lt;a href=&#34;https://github.com/Supervisor/supervisor/blob/master/README.rst&#34;&gt;supervisor 4.0 (unreleased)&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;common-python-3-migration-blockers&#34;&gt;Common Python 3 Migration Blockers&lt;/h3&gt;
&lt;p&gt;You might be aware of atleast one project which is still on Python 2. It could be open source or an internal project, which may be stuck in Python 3 for a number of reasons. I&amp;rsquo;ve come across a number of such projects and here is my response to such reasons:&lt;/p&gt;
&lt;h4 id=&#34;reason-1-my-project-is-too-complex&#34;&gt;Reason 1: My Project is too complex&lt;/h4&gt;
&lt;p&gt;Some very large and complex projects like NumPy or Django have been migrated sucessfully. You can learn the &lt;a href=&#34;https://docs.djangoproject.com/en/1.11/topics/python3/&#34;&gt;migration strategies of projects like Django&lt;/a&gt;. Django maintained a common codebase for Python 2 and 3 using the &lt;a href=&#34;https://pypi.python.org/pypi/six&#34;&gt;six&lt;/a&gt; (2 × 3=6, get it?) library before switching to Python 3 only.&lt;/p&gt;
&lt;h4 id=&#34;reason-2-i-still-have-time&#34;&gt;Reason 2: I still have time&lt;/h4&gt;
&lt;p&gt;It is closer than you think. &lt;a href=&#34;https://pythonclock.org/&#34;&gt;Python clock&lt;/a&gt; shows there is a little more than 2 years and 2 months left for Python 2 support.&lt;/p&gt;
&lt;p&gt;In fact, you have had a lot of time. It has been ten years since Python 3 was announced. That is a lot of overlap to transition from one version to another.&lt;/p&gt;
&lt;p&gt;In today&amp;rsquo;s &amp;lsquo;move fast and break things&amp;rsquo; world, a lot of projects decide to abruptly stop support and ask you to migrate as soon as a new release is out. This is a lot more realistic assumption for enterprises which need a lot more planning and testing.&lt;/p&gt;
&lt;h4 id=&#34;reason-3-i-have-to-learn-python-3&#34;&gt;Reason 3: I have to learn Python 3&lt;/h4&gt;
&lt;p&gt;But you already know most of it! You might need about 10 mins to learn the differences. In fact, I have written a post to guide &lt;a href=&#34;https://arunrocks.com/python-3-cheatsheet-for-djangonauts/&#34;&gt;Django coders to Python 3&lt;/a&gt;. Small Django/Python 2 projects need only trivial changes to work on Python 3.&lt;/p&gt;
&lt;p&gt;You might see many old blog posts about Python 3 being buggy or slow. Well, that has not been true for a while. Not only it is extremely stable and bug-free, it is actually used in production by several companies. Performance-wise it has been getting faster in every release, so it is faster than Python 2 in most cases and slower in a few.&lt;/p&gt;
&lt;p&gt;Of course, there are lot of awesome new features and libraries added to Python 3. You can learn them as and when you need them. I would recommend reading the release notes to understand them. I will mention my favourites soon.&lt;/p&gt;
&lt;h4 id=&#34;reason-4-nobody-is-asking&#34;&gt;Reason 4: Nobody is asking&lt;/h4&gt;
&lt;p&gt;Some people have the philosophy that if nobody is asking then nobody cares. Well, they do care if the application they run is on an unsupported technology. Better plan for the eventual transition than rush it on a higher budget.&lt;/p&gt;
&lt;h2 id=&#34;are-you-missing-out&#34;&gt;Are you missing out?&lt;/h2&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/box-of-chocs.jpg&#34; alt=&#34;Image by https://pixabay.com/en/users/GlenisAymara-856260/&#34;   width=1280 height=&#34;720&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;To me, the biggest reason to switch was that all the newest and greatest features were coming to Python 3. My favourite top three exclusive features in Python 3 are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.python.org/3/library/asyncio.html&#34;&gt;&lt;strong&gt;asyncio&lt;/strong&gt;&lt;/a&gt;: One of the coolest technologies I picked up recently. The learning process is sometimes mind-bending. But the performance boost in the right situations is incredible.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.python.org/3/library/asyncio.html&#34;&gt;&lt;strong&gt;f-strings&lt;/strong&gt;&lt;/a&gt;: They are so incredibly expressive that you would want to use them everywhere. Instant love!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.python.org/3/whatsnew/3.6.html#new-dict-implementation&#34;&gt;dict&lt;/a&gt;: New compact dict implementation which uses less memory and are ordered!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Yes, &lt;a href=&#34;https://en.wikipedia.org/wiki/Fear_of_missing_out&#34;&gt;FOMO&lt;/a&gt; is real.&lt;/p&gt;
&lt;p&gt;Apart from my personal reasons, I would recommend everyone to migrate so that the community benefits from investing efforts into a common codebase. Plus we can all be consistent on which Python to recommend to beginners. &lt;a href=&#34;https://www.python.org/dev/peps/pep-0020/&#34;&gt;Because&lt;/a&gt;&amp;hellip;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There should be one&amp;ndash; and preferably only one &amp;ndash;obvious way to do it.
Although that way may not be obvious at first unless you&amp;rsquo;re Dutch.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class=&#34;series-box&#34;&gt;
&lt;p&gt;This article contains an excerpt from the upcoming second edition of book &lt;a href=&#34;http://djangopatternsbook.github.io/&#34;&gt;&#34;Django Design Patterns and Best Practices&#34;&lt;/a&gt; by Arun Ravindran&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Hangman in more than three lines of Python</title>
      <link>https://arunrocks.com/hangman-more-than-three-lines-python-3/</link>
      <pubDate>Tue, 16 Feb 2016 20:03:00 +0530</pubDate>
      
      <guid>https://arunrocks.com/hangman-more-than-three-lines-python-3/</guid>
      <description>&lt;p&gt;Recently, &lt;a href=&#34;http://danverbraganza.com/writings/hangman-in-3-lines-of-python&#34;&gt;Danver wrote about a brilliant implementation of the Hangman game&lt;/a&gt; in just three lines of Python. But the shortened code might be hard to understand. In this post we will rewrite his code in a more idiomatic Python 3 style.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Spoiler Alert: If you prefer a fun exercise, try doing it yourself first and then compare with my version.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Danver&amp;rsquo;s implementation cleverly uses the system dictionary (pre-installed in Linux and Mac, but we&amp;rsquo;ll see how it can work in Windows too) for picking a random word. It also displays a neat ASCII-art hangman at every step. Except for a few minor improvements, I have tried to retain the essence of Danver&amp;rsquo;s original in my rewrite below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;A simple text-based game of hangman
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;A re-implementation of Hangman 3-liner in more idiomatic Python 3
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;Original: http://danverbraganza.com/writings/hangman-in-3-lines-of-python
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;Requirements:
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;  A dictionary file at /usr/share/dict/words
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;Usage:
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;  $ python hangman.py
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;Released under the MIT License. (Re)written by Arun Ravindran http://arunrocks.com
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;

&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;random&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;DICT&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;/usr/share/dict/words&amp;#39;&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;choice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;open&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DICT&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;readlines&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;upper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;strip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|======
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|   |
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;| {3} {0} {5}
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|  {2}{1}{4}
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|  {6} {7}
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|  {8} {9}
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;|
&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;OT-&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\\&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;-//&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\\&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;||&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;k&#34;&gt;while&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;issuperset&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;{} ({} guesses left)&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;sorted&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;_&amp;#39;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;update&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;upper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;input&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isalpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;You win!&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;You lose!&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;{}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;HANGED!&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;
&lt;span class=&#34;k&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Word was&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can view or download the &lt;a href=&#34;https://gist.github.com/arocks/173ef7d0e2b3d18b6e97&#34;&gt;gist on Github&lt;/a&gt; as well.&lt;/p&gt;
&lt;h3 id=&#34;ho_-it-_orks&#34;&gt;HO_ IT _ORKS&lt;/h3&gt;
&lt;p&gt;The code makes excellent use of Python&amp;rsquo;s built-in &lt;a href=&#34;https://docs.python.org/3.1/tutorial/datastructures.html#sets&#34;&gt;&lt;code&gt;set&lt;/code&gt;&lt;/a&gt; data structure and string &lt;a href=&#34;https://pyformat.info/&#34;&gt;&lt;code&gt;format&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;p&gt;Right after a boring module &lt;a href=&#34;https://www.python.org/dev/peps/pep-0257/&#34;&gt;docstring&lt;/a&gt; and the &lt;code&gt;import&lt;/code&gt; statement, we initialize the following variables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DICT&lt;/strong&gt;: Path to a dictionary file&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;chosen_word&lt;/strong&gt;: Randomly picked line (aka. a word) from DICT&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;guesses&lt;/strong&gt;: Set of letters guessed by the user, so far&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;scaffold&lt;/strong&gt;: Hangman drawn in ASCII art as a format string&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;man&lt;/strong&gt;: Missing ASCII characters for &lt;code&gt;scaffold&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;guesses_left&lt;/strong&gt;: Remaining letter guesses&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;while&lt;/code&gt; loop, whose exit condition will be explained soon, is our main game loop. The first &lt;code&gt;print&lt;/code&gt; function reminds you the guesses you have entered so far (in alphabetic order) and the number of guesses left. The next &lt;code&gt;print&lt;/code&gt; function shows the ASCII hangman with enough missing parts from &lt;code&gt;man&lt;/code&gt; based on the number of wrong guesses.&lt;/p&gt;
&lt;p&gt;Finally, the third &lt;code&gt;print&lt;/code&gt; function shows the &lt;code&gt;chosen_word&lt;/code&gt; by revealing only the characters from your &lt;code&gt;guesses&lt;/code&gt; and replacing the rest with underscores. In the following line, we read a character or even several characters from the user, uppercase them, filter out the non-alphabets and update the &lt;code&gt;guesses&lt;/code&gt; set, all in a single line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;guesses.update(c.upper() for c in input() if str.isalpha(c))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Next, we calculate the number of letters we got wrong. As the diagram below shows, this is the difference of the sets &lt;code&gt;guesses&lt;/code&gt; and &lt;code&gt;chosen_words&lt;/code&gt; (In the diagram, the letters - C,M,T). We find how many guesses are left by subtracting the set of letters of &lt;code&gt;man&lt;/code&gt; from the letters we got wrong. The &lt;code&gt;max&lt;/code&gt; function ensures that we don&amp;rsquo;t go below zero.&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/hangman-venn.png&#34; alt=&#34;Hangman logic explained through sets&#34;   width=750 height=&#34;250&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Eventually, you could win if your guesses cover all the right letters. In the language of sets, this is when &lt;code&gt;guesses&lt;/code&gt; set grows large enough to become a super set of &lt;code&gt;chosen_word&lt;/code&gt; set. This is indicated by the dashed purple circle. Hence, the &lt;code&gt;while&lt;/code&gt; loop will continue until this happens or we run out of remaining guesses.&lt;/p&gt;
&lt;p&gt;Finally, we show a win or lose message based on whether we ran out of guesses. In either case we reveal the initial &lt;code&gt;chosen_word&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;impro_emen_s&#34;&gt;IMPRO_EMEN_S&lt;/h3&gt;
&lt;p&gt;For comparison, here is Danver&amp;rsquo;s original three-liner:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;n&#34;&gt;license&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;https://opensource.org/licenses/MIT&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isalpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;__import__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;random&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;choice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;open&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;/usr/share/dict/words&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;readlines&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;upper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())),&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;|======&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;|   |&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;| {3} {0} {5}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;|  {2}{1}{4}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;|  {6} {7}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;|  {8} {9}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;|&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;list&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;OT-&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\\&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;-//&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\\&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;||&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;
&lt;span class=&#34;k&#34;&gt;while&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;all&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;map&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;add&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isalpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;raw_input&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;%s&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;%s&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt; guesses left)&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;%s&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;%s&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;:&amp;#39;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;sorted&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[:&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;_&amp;#39;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;letter&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;upper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())),&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;k&#34;&gt;print&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;You&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;lose!&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scaffold&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;man&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;win!&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;][&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;bool&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guesses_left&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)],&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;Word was&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;chosen_word&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Got it? Okay, maybe it needs a bit of explanation. Python is a whitespace-aware language designed for maximum readability. So it takes a lot of questionable tricks to write one-liners, some of which I have used myself in my post &lt;a href=&#34;http://arunrocks.com/python-one-liner-games/&#34;&gt;&amp;ldquo;Python One-liner Games&amp;rdquo;&lt;/a&gt;. This time we are going in the opposite direction.&lt;/p&gt;
&lt;p&gt;Probably, the most visible changes are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;License&lt;/strong&gt;: Mentioned in a doc string rather than as a string&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Import&lt;/strong&gt;: No longer need to use the internal &lt;code&gt;__import__&lt;/code&gt; function&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scaffold&lt;/strong&gt;: Multi-line string rather than a one-liner&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Print&lt;/strong&gt;: Changed from a statement to a function, as in Python 3&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Raw_input&lt;/strong&gt;: Changed to an &lt;code&gt;input&lt;/code&gt; function, as in Python 3&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C-style %s formats&lt;/strong&gt;: Replaced with &lt;code&gt;str.format&lt;/code&gt; everywhere&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But, there are also some less evident code changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Loop condition&lt;/strong&gt;: Replaced list comprehension in &lt;code&gt;while&lt;/code&gt; condition with a superset check&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Negative index&lt;/strong&gt;: No need of &lt;code&gt;man[:10-guesses_left]&lt;/code&gt;, just &lt;code&gt;man[:-guesses_left]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set update&lt;/strong&gt;: Replace &lt;code&gt;map&lt;/code&gt;/&lt;code&gt;filter&lt;/code&gt; with a &lt;code&gt;set.update&lt;/code&gt; i.e. from this:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;    map(guesses.add, filter(str.isalpha, raw_input...

with this:

    guesses.update(c.upper() for c in input() if str.isalpha(c))
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Magic numbers&lt;/strong&gt;: The number 10 is no longer hard-coded and replaced with &lt;code&gt;len(man)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As you can see, I have preferred set functions over list comprehensions. The choice of set functions like &lt;code&gt;my_set.update&lt;/code&gt; over set operators like &lt;code&gt;my_set +=&lt;/code&gt; was intentional as the former allows any iterable as an argument and not just sets. In most cases, I have used &lt;a href=&#34;https://docs.python.org/2/reference/expressions.html#generator-expressions&#34;&gt;generator expressions&lt;/a&gt; for efficiency.&lt;/p&gt;
&lt;h3 id=&#34;w_y-pyt_on-3&#34;&gt;W_Y PYT_ON 3?&lt;/h3&gt;
&lt;p&gt;I must admit that the actual reason I rewrote the Hangman was because it didn&amp;rsquo;t work on my Arch Linux box, which runs on Python 3. Over the last few months, I have completely switched over all my projects (and &lt;a href=&#34;http://djangopatternsbook.github.io/&#34;&gt;my book&lt;/a&gt;) to Python 3. So far I have had no reason to complain.&lt;/p&gt;
&lt;p&gt;Apart from the syntactic differences, you will find some solid advantages of using Python 3 versus Python 2:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unicode files&lt;/strong&gt;: Since the dictionary file path can be changed, I created a test file with a few &lt;a href=&#34;https://en.wikipedia.org/wiki/Malayalam&#34;&gt;Malayalam&lt;/a&gt; words in separate lines. The Python 2 version just exits with a win message. This is probably because &lt;code&gt;str.isalpha&lt;/code&gt; filters out all the characters. Whereas, in Python 3, everything just works.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Removes arcane forms&lt;/strong&gt;: No more &lt;code&gt;raw_input&lt;/code&gt; (who uses the old &lt;code&gt;input&lt;/code&gt;?) or &lt;code&gt;print&lt;/code&gt; statements&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you are on Windows, you can download pretty much &lt;a href=&#34;https://github.com/buddingmonkey/WordGameDictionary/raw/master/Dictionaries/ospd.txt&#34;&gt;any of&lt;/a&gt; the &lt;a href=&#34;https://github.com/Glutanimate/wordlist-medicalterms-en/raw/master/wordlist.txt&#34;&gt;dictionaries online&lt;/a&gt; (even the &lt;a href=&#34;http://www.cs.cmu.edu/~biglou/resources/bad-words.txt&#34;&gt;offensive&lt;/a&gt; ones) and change the path in &lt;code&gt;DICT&lt;/code&gt; to something like &lt;code&gt;dict.txt&lt;/code&gt;. Or, you can create a simple text file with one word on each line. Pro Tip: Hangman is great for learning foreign languages so try creating a Unicode file with some foreign language words.&lt;/p&gt;
&lt;p&gt;Before any of the Python 2 fans lash out on me, let me note in the passing that this code will work perfectly on Python 2.7+ if you replace &lt;code&gt;input&lt;/code&gt; with &lt;code&gt;raw_input&lt;/code&gt;. Cheers!&lt;/p&gt;
&lt;h3 id=&#34;fi_al-comme_t&#34;&gt;FI_AL COMME_T&lt;/h3&gt;
&lt;p&gt;This post is by no means a critique of Danver&amp;rsquo;s code. In fact, I loved his implementation and totally didn&amp;rsquo;t waste my weekend playing Hangman (27 wins out of 30 games!!!). It had a lot of fun mapping the problem to sets and making small improvements.&lt;/p&gt;
&lt;p&gt;Hope you found some new Python best practices or just an awesome word game to kill time!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Python 3 Cheatsheet for Djangonauts</title>
      <link>https://arunrocks.com/python-3-cheatsheet-for-djangonauts/</link>
      <pubDate>Wed, 20 May 2015 19:08:00 +0530</pubDate>
      
      <guid>https://arunrocks.com/python-3-cheatsheet-for-djangonauts/</guid>
      <description>&lt;p&gt;&lt;strong&gt;If you are already convinced to use Python 3 then you can directly jump to the section &lt;a href=&#34;#python-2-vs-python-3&#34;&gt;&amp;ldquo;Python 2 vs Python 3&amp;rdquo;&lt;/a&gt; for the cheatsheet&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There is an intense debate whenever Python 3 is mentioned. Some think it is an unnecessary shift and Python 2 series should be continued. However, I chose Python 3 for my &lt;a href=&#34;http://djangopatternsbook.github.io/&#34;&gt;book&lt;/a&gt; because I strongly believe that it is the future of the language. Besides, the divide might not be as large you think.&lt;/p&gt;
&lt;h3 id=&#34;why-python-3&#34;&gt;Why Python 3?&lt;/h3&gt;
&lt;p&gt;Think of your favourite programming language and what you love about it. Now think of things that you don&amp;rsquo;t like about it or wish was improved. Sometimes these improvements might break older codebases but you badly want them.&lt;/p&gt;
&lt;p&gt;Now imagine if the creator of the language takes upon himself/herself to revamp the language and rid of its warts. This is what actually led to Python 3 - Guido led the efforts to clean-up some fundamental design flaws with the 2.x series based on over fifteen years of experience developing a successful language.&lt;/p&gt;
&lt;p&gt;While the development of Python 3 started in 2006, its first release, Python 3.0, was on December 3, 2008. The main reasons for a backwards incompatible version were – switching to Unicode for all strings, increased use of iterators, cleanup of deprecated features like old-style classes and some new syntactic additions like the &lt;code&gt;nonlocal&lt;/code&gt; statement.&lt;/p&gt;
&lt;p&gt;Python 2.7 development was supposed to end in 2015 but was extended for five more years through 2020. There will not be a Python 2.8. Soon all major Linux distributions would have completely switched to using Python 3 as a default. Many PaaS providers like Heroku already support Python 3.4.&lt;/p&gt;
&lt;p&gt;Python 2 and Python 3 have been in parallel development by the core development team for a number of years. Eventually, Python 3 is expected to be the future of the language.&lt;/p&gt;
&lt;h3 id=&#34;porting-django&#34;&gt;Porting Django&lt;/h3&gt;
&lt;p&gt;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 migration effort.&lt;/p&gt;
&lt;p&gt;Django has been supporting Python 3 since version 1.5. In fact, the strategy was to rewrite the code into Python 3 and deal with Python 2 as a backward compatibility requirement.&lt;/p&gt;
&lt;p&gt;Most of the packages listed in the &lt;a href=&#34;https://python3wos.appspot.com/&#34;&gt;Python 3 Wall of Superpowers&lt;/a&gt; have turned green (indicating they have support for Python 3). Almost all the red ones have an actively developed Python 3 port. Also worth noting is the &lt;a href=&#34;http://djangowos.com/&#34;&gt;Django Wall of Superpowers&lt;/a&gt; with over 67% of the top 200 Django packages having a Python 3 port.&lt;/p&gt;
&lt;h3 id=&#34;python-3-advantage&#34;&gt;Python 3 Advantage&lt;/h3&gt;
&lt;p&gt;Many newcomers to Django wonder whether to start using Python 2 or 3. I recommend starting with Python 3 for the following reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Better syntax&lt;/strong&gt;: It fixes a lot of ugly syntax like &lt;code&gt;izip&lt;/code&gt;, &lt;code&gt;xrange&lt;/code&gt; and &lt;code&gt;__unicode__&lt;/code&gt; with the cleaner and more straightforward &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;range&lt;/code&gt; and &lt;code&gt;__str__&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sufficient third-party support&lt;/strong&gt;: Of the top 200 third party libraries, more than 80% have Python 3 support.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No legacy code&lt;/strong&gt;: Since they are creating a new project rather than dealing with legacy code which needs to support an older version.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Default in Modern Platforms&lt;/strong&gt;: It is already  the default Python interpreter in Arch Linux. Ubuntu and Fedora plan to complete the switch in a future release.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It is easy&lt;/strong&gt;: From a Django development point of view, there are so few changes that it can be learnt in a few minutes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The last point is important. Even if you know Python 2, you can pick up Python 3 in a short time.&lt;/p&gt;
&lt;h2 id=&#34;python-2-vs-python-3&#34;&gt;Python 2 vs Python 3&lt;/h2&gt;
&lt;p&gt;This section covers the most important changes in Python 3 from a Django developer&amp;rsquo;s perspective. To understand the full list of changes, please refer to the recommended reading section in the end.&lt;/p&gt;
&lt;p&gt;The examples are given in both Python 2 and Python 3. Depending on your installation, all Python 3 commands might need to be changed from &lt;code&gt;python&lt;/code&gt; to &lt;code&gt;python3&lt;/code&gt; or &lt;code&gt;python3.4&lt;/code&gt; to invoke the interpreter.&lt;/p&gt;
&lt;h3 id=&#34;change-all-__unicode__-methods-into-__str__&#34;&gt;Change all __unicode__ methods into __str__&lt;/h3&gt;
&lt;p&gt;In Python 3, the &lt;code&gt;__str__()&lt;/code&gt; method is called for string representation of your models rather than the awkward sounding &lt;code&gt;__unicode__()&lt;/code&gt; method. This is one of the most evident ways to identify Python 3 ported code.&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
&lt;p&gt;class Person(models.Model):
name = models.TextField()&lt;/p&gt;
&lt;p&gt;def &lt;strong&gt;unicode&lt;/strong&gt;(self):
return self.name&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
  &lt;td&gt;&lt;pre&gt;
&lt;p&gt;class Person(models.Model):
name = models.TextField()&lt;/p&gt;
&lt;p&gt;def &lt;strong&gt;str&lt;/strong&gt;(self):
return self.name&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This reflects the difference in the way Python 3 treats strings. In Python 2, the human readable representation of a class could be returned by &lt;code&gt;__str__()&lt;/code&gt; (bytes) or &lt;code&gt;__unicode__()&lt;/code&gt; (text). However, in Python 3 the readable representation is simply returned by &lt;code&gt;__str__()&lt;/code&gt; (text).&lt;/p&gt;
&lt;h3 id=&#34;all-classes-inherit-from-object&#34;&gt;All Classes Inherit from object&lt;/h3&gt;
&lt;p&gt;Python 2 has two kinds of classes – old-style (classic) and new-style. New-style classes are classes which directly or indirectly inherit from &lt;code&gt;object&lt;/code&gt;. Only new style classes can use Python&amp;rsquo;s advanced features like slots, descriptors and properties. Many of these are used by Django. However, classes were still old-style by default for compatibility reasons.&lt;/p&gt;
&lt;p&gt;In Python 3, the old-style classes don&amp;rsquo;t exist anymore. As seen below, even if you don&amp;rsquo;t explicitly mention any parent classes the &lt;code&gt;object&lt;/code&gt; class will be present as a base. So, all classes are new-style.&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; class CoolMixin:
&amp;hellip;     pass
&amp;gt;&amp;gt;&amp;gt; CoolMixin.&lt;strong&gt;bases&lt;/strong&gt;
()&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
  &lt;td&gt;&lt;pre&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; class CoolMixin:
&amp;hellip;     pass
&amp;gt;&amp;gt;&amp;gt; CoolMixin.&lt;strong&gt;bases&lt;/strong&gt;
(&amp;lt;class &amp;lsquo;object&amp;rsquo;&amp;gt;,)&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;calling-super-is-easier&#34;&gt;Calling super() is Easier&lt;/h3&gt;
&lt;p&gt;The simpler call to &lt;code&gt;super()&lt;/code&gt;, without any arguments, will save you some typing in Python 3.&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
class CoolMixin(object):
&lt;p&gt;def do_it(self):
return super(CoolMixin,
self).do_it()
&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
  &lt;td&gt;&lt;pre&gt;
class CoolMixin:
&lt;p&gt;def do_it(self):
return super().do_it()
&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Specifying the class name and instance is optional, thereby making your code DRY and less prone to errors while refactoring.&lt;/p&gt;
&lt;h3 id=&#34;relative-imports-must-be-explicit&#34;&gt;Relative Imports Must be Explicit&lt;/h3&gt;
&lt;p&gt;Imagine the following directory structure for a package named &lt;code&gt;app1&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/app1
  /__init__.py
  /models.py
  /tests.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, in Python 3, let us run the following in the parent directory of &lt;code&gt;app1&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ echo &amp;quot;import models&amp;quot; &amp;gt; app1/tests.py
$ python -m app1.tests
Traceback (most recent call last):
   ... omitted ...
ImportError: No module named &#39;models&#39;
$ echo &amp;quot;from . import models&amp;quot; &amp;gt; app1/tests.py
$ python -m app1.tests
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&#34;successfully-import-ed&#34;&gt;Successfully import-ed&lt;/h4&gt;
&lt;p&gt;Within a package, you should use explicit relative imports while referring to a sibling module. You can omit &lt;code&gt;__init__.py&lt;/code&gt; in Python 3, though it is commonly used to identify a package.&lt;/p&gt;
&lt;p&gt;In Python 2, you could use &lt;code&gt;import models&lt;/code&gt; to successfully import &lt;code&gt;models.py&lt;/code&gt; module. But it was ambiguous and could accidentally import any other &lt;code&gt;models.py&lt;/code&gt; in your Python path. Hence this is forbidden in Python 3 and discouraged in Python 2 as well. Use &lt;code&gt;from . import models&lt;/code&gt; instead.&lt;/p&gt;
&lt;h3 id=&#34;httprequest-and-httpresponse-have-str-and-bytes-types&#34;&gt;HttpRequest and HttpResponse have str and bytes Types&lt;/h3&gt;
&lt;p&gt;In Python 3, according to PEP 3333 (amendments to the WSGI standard), we are careful not to mix data coming from or leaving via HTTP, which will be in bytes; as opposed to text within the framework, which will be native (Unicode) strings.&lt;/p&gt;
&lt;p&gt;Essentially, for &lt;code&gt;HttpRequest&lt;/code&gt; and &lt;code&gt;HttpResponse&lt;/code&gt; objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Headers will be always str objects&lt;/li&gt;
&lt;li&gt;Input and output streams will be always byte objects&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Unlike Python 2, the string and bytes are not implicitly converted while performing comparisons or concatenations with each other. Strings mean Unicode strings only.&lt;/p&gt;
&lt;h3 id=&#34;exception-syntax-changes-and-improvements&#34;&gt;Exception Syntax Changes and Improvements&lt;/h3&gt;
&lt;p&gt;Exception handling syntax and functionality has been significantly improved in Python 3.&lt;/p&gt;
&lt;p&gt;In Python 3, you cannot use the comma separated syntax for the except clause. Use the &lt;code&gt;as&lt;/code&gt; keyword instead:&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
try:
  pass
except BaseException, e:
  pass
  &lt;/pre&gt;&lt;/td&gt;
  &lt;td&gt;&lt;pre&gt;
try:
  pass
except BaseException as e:
  pass
  &lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The new syntax is recommended for Python 2 as well.&lt;/p&gt;
&lt;p&gt;In Python 3, all exceptions must be derived (directly or indirectly) from &lt;code&gt;BaseException&lt;/code&gt;. In practice, you would create your custom exceptions by deriving from the &lt;code&gt;Exception&lt;/code&gt; class.&lt;/p&gt;
&lt;p&gt;As a major improvement in error reporting, if an exception occurs while handling an exception then the entire chain of exceptions are reported:&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
&gt;&gt;&gt; try:
...   print(undefined)
... except Exception:
...   print(oops)
...
Traceback (most recent call last):
  File &#34;&lt;stdin&gt;&#34;, line 4, in &amp;lt;module&amp;gt;
  NameError: name &#39;oops&#39; is not defined
&lt;/pre&gt;&lt;/td&gt;
  &lt;td&gt;&lt;pre&gt;
&gt;&gt;&gt; try:
...   print(undefined)
... except Exception:
...   print(oops)
...
Traceback (most recent call last):
  File &#34;&amp;lt;stdin&amp;gt;&#34;, line 2, in &amp;lt;module&amp;gt;
  NameError: name &#39;undefined&#39; is not defined
&lt;p&gt;During the handling of the preceding
exception, another exception occurred:&lt;/p&gt;
&lt;p&gt;Traceback (most recent call last):
File &amp;ldquo;&amp;lt;stdin&amp;gt;&amp;rdquo;, line 4, in &amp;lt;module&amp;gt;
NameError: name &amp;lsquo;oops&amp;rsquo; is not defined&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/p&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Once you get used to this feature, you will definitely miss it in Python 2.&lt;/p&gt;
&lt;h3 id=&#34;standard-library-reorganized&#34;&gt;Standard Library Reorganized&lt;/h3&gt;
&lt;p&gt;The core developers have cleaned-up and better organized the Python standard library. For instance &lt;code&gt;SimpleHTTPServer&lt;/code&gt; now lives in the &lt;code&gt;http.server&lt;/code&gt; module:&lt;/p&gt;
&lt;table class=&#34;sidebyside&#34;&gt;
  &lt;thead&gt;
&lt;tr&gt;
  &lt;th&gt;Python 2&lt;/th&gt;
  &lt;th&gt;Python 3&lt;/th&gt;
&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;pre&gt;
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
  &lt;/pre&gt;&lt;/td&gt;
  &lt;td&gt;&lt;pre&gt;
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 ...
  &lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;new-goodies&#34;&gt;New Goodies&lt;/h3&gt;
&lt;p&gt;Python 3 is not just about language fixes. It is also where bleeding-edge Python development happens. This means improvements to the language in terms of syntax, performance and built-in functionality.&lt;/p&gt;
&lt;p&gt;Some of the notable new modules added to Python 3 are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;asyncio&lt;/code&gt; : Asynchronous I/O, event loop, coroutines and tasks&lt;/li&gt;
&lt;li&gt;&lt;code&gt;unittest.mock&lt;/code&gt; : Mock object library for testing&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pathlib&lt;/code&gt; : Object-oriented filesystem paths&lt;/li&gt;
&lt;li&gt;&lt;code&gt;statistics&lt;/code&gt; : Mathematical statistics functions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even if some of these modules might have backports to Python 2, it is more appealing to migrate to Python 3 and leverage them as built-in modules.&lt;/p&gt;
&lt;h4 id=&#34;pyvenv-and-pip-are-built-in&#34;&gt;Pyvenv and Pip are Built-in&lt;/h4&gt;
&lt;p&gt;Most serious Python developers prefer to use virtual environments. virtualenv is quite popular to isolate your project setup from the system-wide Python installation. Thankfully, Python 3.3 is integrated with a similar functionality using the &lt;code&gt;venv&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;Since Python 3.4, a fresh virtual environment will be pre-installed with pip, a popular installer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ python -m venv djenv
[djenv] $ source djenv/bin/activate
[djenv] $ pip install django
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice that the command prompt changes to indicate that your virtual environment has been activated.&lt;/p&gt;
&lt;h3 id=&#34;other-changes&#34;&gt;Other Changes&lt;/h3&gt;
&lt;p&gt;We cannot possibly fit all the Python 3 changes and improvements in this post. But the other commonly cited changes are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;print is now a function&lt;/strong&gt; : Previously it was a statement i.e. arguments were not in parenthesis.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integers don&amp;rsquo;t overflow&lt;/strong&gt; : &lt;code&gt;sys.maxint&lt;/code&gt; is outdated, integers will have unlimited precision.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inequality operator &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; is removed&lt;/strong&gt; : Use &lt;code&gt;!=&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;True Integer Division&lt;/strong&gt; : In Python 2, &lt;code&gt;3 / 2&lt;/code&gt; would evaluate to 1. It will be correctly evaluated to &lt;code&gt;1.5&lt;/code&gt; in Python 3.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;code&gt;range&lt;/code&gt; instead of &lt;code&gt;xrange&lt;/code&gt;&lt;/strong&gt; : &lt;code&gt;range()&lt;/code&gt; will now return iterators as &lt;code&gt;xrange()&lt;/code&gt; used to work before.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dictionary keys are views&lt;/strong&gt; : &lt;code&gt;dict&lt;/code&gt; and &lt;code&gt;dict&lt;/code&gt;-like classes (like &lt;code&gt;QueryDict&lt;/code&gt;) will return iterators instead of lists for &lt;code&gt;keys()&lt;/code&gt;, &lt;code&gt;items()&lt;/code&gt; and &lt;code&gt;values()&lt;/code&gt; method calls.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;series-box&#34;&gt;
&lt;p&gt;This article is an excerpt from the book &lt;a href=&#34;http://djangopatternsbook.github.io/&#34;&gt;&#34;Django Design Patterns and Best Practices&#34;&lt;/a&gt; by Arun Ravindran&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Read &lt;em&gt;What&amp;rsquo;s New In Python 3.0&lt;/em&gt; by Guido &lt;a href=&#34;https://docs.python.org/3/whatsnew/3.0.html&#34;&gt;https://docs.python.org/3/whatsnew/3.0.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;To find what is new in each release of Python, read _What&amp;rsquo;s New in Python_&lt;a href=&#34;https://docs.python.org/3/whatsnew/&#34;&gt;https://docs.python.org/3/whatsnew/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;For richly detailed answers about Python 3 read &lt;em&gt;Python 3 Q &amp;amp; A&lt;/em&gt; by Nick Coghlan &lt;a href=&#34;http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html&#34;&gt;http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Introducing Edge - a Modern Django Project Template</title>
      <link>https://arunrocks.com/introducing-edge-a-modern-django-project-template/</link>
      <pubDate>Mon, 22 Sep 2014 08:19:00 +0530</pubDate>
      
      <guid>https://arunrocks.com/introducing-edge-a-modern-django-project-template/</guid>
      <description>&lt;p&gt;&lt;strong&gt;A newer version has been &lt;a href=&#34;https://arunrocks.com/edge-v2/&#34;&gt;announced&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Have you ever begun creating a web app only to abandon it while setting it up? I have done it more times than I would have liked.&lt;/p&gt;
&lt;p&gt;Many programming environments involve so much ritual to setup that we tend to forget what we set out to create. Recently, I had to setup an Android development environment from scratch. Despite downloading the latest version of the IDE, I waited until several additional updates downloaded to patch it to the latest version. The trend of packages getting more granular and updates being made several times a day is here to stay.&lt;/p&gt;
&lt;p&gt;It is like if you have an idea for a painting then you have to go shopping for all the art-supplies first. But the moment you step out, you have lost your muse. Scientists call this &lt;a href=&#34;http://en.wikipedia.org/wiki/Encoding_specificity_principle&#34;&gt;encoding specificity&lt;/a&gt; or as a famous paper calls it &lt;a href=&#34;http://www.tandfonline.com/doi/abs/10.1080/17470218.2011.571267&#34;&gt;“Walking through doorways causes forgetting.”&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;django-projects&#34;&gt;Django Projects&lt;/h2&gt;
&lt;p&gt;Of course, in Django I use &lt;code&gt;startproject&lt;/code&gt; which builds an excellent but minimal project structure. But once I start coding I inevitably tend to install packages like the django braces. Most of my project use Bootstrap, so I end up downloading the bootstrap assets as well. Any non-trivial web app needs some login functionality, so I end up adding that too.&lt;/p&gt;
&lt;p&gt;In short, by the time I have setup everything to actually start building the app, I have crossed the doorway and forgotten most of the idea. And lost a bit of the enthusiasm too.
Edge - for Django Projects in 2014&lt;/p&gt;
&lt;p&gt;So, I created Edge. I believe Edge is a great starting point for Django projects. It comes with Bootstrap assets (even for the admin), basic user sign up flows and a sensible set of default settings. Most importantly, it is built for Django 1.7 and Python 3.4, the latest versions at the time of writing.&lt;/p&gt;
&lt;p&gt;As soon as you start your project in edge, you will notice that it has a great looking and functional home page rather than Django’s familiar blue “It Worked!” page. The appearance is much closer to what you expect as a starting point for your app. Check it out yourself in the short demo below.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=8cCM18J4Nw4&#34;&gt;&lt;img src=&#34;https://arunrocks.com/static/images/blog/edge.png&#34; width=&#34;500&#34; height=&#34;281&#34; alt=&#34;Edge demo video&#34; title=&#34;Go to the Demo on YouTube&#34;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;motivations&#34;&gt;Motivations&lt;/h2&gt;
&lt;p&gt;Things I found missing or inadequate with the default Django project structure&lt;/p&gt;
&lt;h3 id=&#34;iconic-omissions&#34;&gt;Iconic Omissions&lt;/h3&gt;
&lt;p&gt;It started with the small things. Doesn’t it always? Every time I noticed a 404 while developing a Django application I had to calm myself down - don’t worry, it is just a missing favicon.&lt;/p&gt;
&lt;img src=&#34;https://arunrocks.com/static/images/blog/edge-favicon.png&#34; width=&#34;660&#34; height=&#34;371&#34; alt=&#34;Missing Favicon&#34; title=&#34;404 due to missing favicon&#34;/&gt;
&lt;p&gt;I know I would eventually add a favicon in production. But I kind of turned blind to errors on my test server logs. The fix was to add a favicon, of course.&lt;/p&gt;
&lt;h3 id=&#34;template-and-static-paths&#34;&gt;Template and Static paths&lt;/h3&gt;
&lt;p&gt;Another one of those small things that I would always need to specify to my settings.py. I understand why the paths are not there. But during developing, it would be so much more convenient, if these directories were present and added to settings.&lt;/p&gt;
&lt;h3 id=&#34;pathlib&#34;&gt;Pathlib&lt;/h3&gt;
&lt;p&gt;Talking about paths, the awkward &lt;code&gt;os.path.join(BASE_DIR, “templates”)&lt;/code&gt; call is needed anymore. Edge uses the new &lt;a href=&#34;https://docs.python.org/3/library/pathlib.html&#34;&gt;&lt;code&gt;pathlib&lt;/code&gt;&lt;/a&gt; library in Python 3.4 instead. The new syntax &lt;code&gt;BASE_DIR / “templates”&lt;/code&gt; is much more convenient and readable.&lt;/p&gt;
&lt;h3 id=&#34;bootstrap&#34;&gt;Bootstrap&lt;/h3&gt;
&lt;p&gt;It is 2014 and hardly anybody starts with a blank page (I mean, blank HTML and CSS) anymore. In fact, most people I know start with a minimal Bootstrap 3 template.&lt;/p&gt;
&lt;p&gt;There are many good packages for using bootstrap in Django. But edge doesn’t use any of them because it is becomes another dependency that sometimes lags behind the rapid development cycle of Bootstrap. Instead, bootstrap assets have been directly included in the static folder. Updating is now easier, just copy the latest versions into the appropriate paths.&lt;/p&gt;
&lt;h3 id=&#34;user-authentication&#34;&gt;User Authentication&lt;/h3&gt;
&lt;p&gt;Django has a built-in user model. It is the base for the admin interface and countless other packages. But a simple user sign-up, login and logout workflow needs quite a bit of work to setup.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://django-registration.readthedocs.org/en/latest/&#34;&gt;Django registrations&lt;/a&gt; was often used for this but has been inactive for a while. Even though &lt;a href=&#34;https://github.com/pennersr/django-allauth&#34;&gt;Django allauth&lt;/a&gt; is an excellent solution in production, I would hardly use social login in my development environment.&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;edge&lt;/em&gt;, a simple sign-up and login form has been provided using crispy forms and class based generic views. It does not do email verification or need a dummy mail server setup. But it helps you prototype and build web apps that can be shown to users for early testing.&lt;/p&gt;
&lt;h3 id=&#34;admin&#34;&gt;Admin&lt;/h3&gt;
&lt;p&gt;“What is this Django Administration?” If only I had a nickel every time someone asked me this. Most projects continue to have their admin interface titled that way even in production.&lt;/p&gt;
&lt;p&gt;The admin interface’s appearance also looks quite antiquated. Try opening it on a mobile device. The edge template uses &lt;a href=&#34;https://github.com/django-admin-bootstrapped/django-admin-bootstrapped&#34;&gt;&lt;code&gt;django-admin-bootstrapped&lt;/code&gt;&lt;/a&gt; to give it a Bootstrap 3 theme. Also, it customises the heading to “&lt;em&gt;MyProject&lt;/em&gt; Administration”.&lt;/p&gt;
&lt;h3 id=&#34;alternate-project-templates&#34;&gt;Alternate Project Templates&lt;/h3&gt;
&lt;p&gt;There are many good project templates already available. I did try using django-twoscoops-project, django-base-template, django-project-skel etc. Some of them did not work properly in Python 3. Others seemed too bloated.&lt;/p&gt;
&lt;p&gt;Project templates are a subjective choice. While I prefer a template with all the necessary settings to start focusing on the problem at hand, I find packages like Celery in the bells and whistles category. Using a project template generator like cookiecutter was also something I never preferred.&lt;/p&gt;
&lt;h2 id=&#34;my-solution---edge&#34;&gt;My solution - edge&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/arocks/edge/wiki&#34;&gt;Edge&lt;/a&gt; has everything what I expect to be in a Django 1.7 and Python 3.4 project. I have used &lt;em&gt;edge&lt;/em&gt; in a couple of projects and look forward to using it in my future projects. It is my new baseline.&lt;/p&gt;
&lt;p&gt;More details about the features and future plans are on the &lt;a href=&#34;https://github.com/arocks/edge/wiki&#34;&gt;wiki&lt;/a&gt;. The project itself is open source and on &lt;a href=&#34;https://github.com/arocks/edge&#34;&gt;Github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I would love to hear your feedback.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Recreating the &#34;Building a Blog in Django&#34; Screencast</title>
      <link>https://arunrocks.com/recreating-the-building-a-blog-in-django-screencast/</link>
      <pubDate>Sun, 06 Jul 2014 18:56:00 +0530</pubDate>
      
      <guid>https://arunrocks.com/recreating-the-building-a-blog-in-django-screencast/</guid>
      <description>&lt;p&gt;Few days back, &lt;a href=&#34;https://www.djangoproject.com/weblog/2014/jun/26/17rc1/&#34;&gt;Django 1.7 release candidate 1&lt;/a&gt; was announced. I have never been so excited about a release in recent memory. It has a new app loading framework and schema migrations baked right in!&lt;/p&gt;
&lt;p&gt;It is also the significant release that I had been waiting for to update &lt;a href=&#34;https://www.youtube.com/watch?v=srHZoj3ASmk&#34;&gt;my original Django screencast&lt;/a&gt;. With more than 77 thousand views, it is by far the most popular Django screencast on YouTube.&lt;/p&gt;
&lt;p&gt;Back in 2012, when I was working in Django, there were a lot of comparisons between Rails and Django. One of the biggest selling points of Ruby on Rails was their official 15-minute blog screencast. It was fascinating to watch an expert Rails developer build an entire site from scratch especially how deftly they use TextMate, which could nearly read his mind.&lt;/p&gt;
&lt;p&gt;Armed with a Linux terminal and Emacs, I set out to create a similar screencast for anyone interested in Django. Live coding was something that I had not tried before. I remember starting at 11 pm one night, hoping to complete my recording by midnight.&lt;/p&gt;
&lt;iframe src=&#34;https://www.flickr.com/photos/joshlewis/1596018210/player/f367327780&#34; height=&#34;375&#34; width=&#34;500&#34;  frameborder=&#34;0&#34; allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;But by the time I finished a recording without any &lt;em&gt;major&lt;/em&gt; goofups it was 5 am in the morning. So with barely any editing, I directly uploaded the raw footage to YouTube and hit the bed.&lt;/p&gt;
&lt;p&gt;Over time, a lot of people have loved the screencast, often asking how they can setup their development environment to resemble mine. Emacs despite not being an IDE is often as productive or more, depending on how well you customise it.&lt;/p&gt;
&lt;h3 id=&#34;why-the-remake&#34;&gt;Why the Remake?&lt;/h3&gt;
&lt;p&gt;I have done several more Django screencasts after that, preferring to demonstrate entire projects in Django rather than focus on a specific feature. But the original still remains a favourite as it is beginner-friendly and short.&lt;/p&gt;
&lt;p&gt;Plenty of new cool features like Class-based Views had come to Django since then. I also noted that there were very few tutorials which used Python 3. For starting a new Django project, I would definitely recommend Python 3.&lt;/p&gt;
&lt;p&gt;So, I decided to remake it but even shorter. Crazily enough, I wanted to cover a lot more than the first screencast. Here are the topics I wanted to touch upon (ones which were not covered in the first screencast are in bold):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;New 1.7 defaults&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Syntax changes in Python 3.4&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;QuerySets and Custom Managers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Admin and ModelAdmin&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rich-text posts with django-markdown&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generic Class-based Views&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Tags&lt;/li&gt;
&lt;li&gt;RSS Feeds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Migrations&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Running testcases&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thankfully, Django 1.7 comes with great project defaults like a predefined SQLite 3 database and admin URLs setup, which gives you a running start. Migrations is a real time-saver as you don&amp;rsquo;t have to keep re-entering your test data.&lt;/p&gt;
&lt;p&gt;The entire recording clocked slightly above 15 mins. Here is the final video and the text version below it:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=7rgph8en0Jc&#34;&gt;&lt;img src=&#34;https://arunrocks.com/static/images/blog/qblog.png&#34; width=&#34;500&#34; height=&#34;352&#34; alt=&#34;Screencast&#34; title=&#34;Go to the Screencast on YouTube&#34;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;People have translated my tutorials into various languages in the past. So I have added subtitles to this screencast. Enjoy the automatic translations in your preferred language!&lt;/p&gt;
&lt;h3 id=&#34;text-version&#34;&gt;Text Version&lt;/h3&gt;
&lt;p&gt;Some prefer to read the transcript of the screencast. Assuming you already have Django 1.7 installed in Python 3.4, you can follow these steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Start the project&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;    django-admin startproject qblog
    cd qblog
    ./manage.py migrate
    ./manage.py createsuperuser
    ./manage.py runserver
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;Add an app called &lt;code&gt;blog&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;    ./manage startapp blog
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;Open &lt;code&gt;blog/models.py&lt;/code&gt; and change its contents to:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.db&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.core.urlresolvers&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;reverse&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;EntryQuerySet&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;QuerySet&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;published&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;publish&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;title&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;CharField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;max_length&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;body&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TextField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;slug&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SlugField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;max_length&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;unique&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;publish&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;BooleanField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;default&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;created&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DateTimeField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;auto_now_add&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;modified&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DateTimeField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;auto_now&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

        &lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;EntryQuerySet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;as_manager&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;fm&#34;&gt;__str__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;title&lt;/span&gt;

        &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Meta&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;verbose_name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Blog Entry&amp;#34;&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;verbose_name_plural&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Blog Entries&amp;#34;&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;ordering&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;-created&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;4&#34;&gt;
&lt;li&gt;In &lt;code&gt;qblog/settings.py&lt;/code&gt; add &lt;code&gt;&amp;quot;blog&amp;quot;&lt;/code&gt; to INSTALLED_APPS and migrate:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;    ./manage.py makemigrations blog
    ./manage.py migrate blog
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;5&#34;&gt;
&lt;li&gt;Change &lt;code&gt;blog/admin.py&lt;/code&gt; to:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.contrib&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;EntryAdmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ModelAdmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;list_display&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;title&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;created&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;prepopulated_fields&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;slug&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;title&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,)}&lt;/span&gt;

    &lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;site&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;register&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;EntryAdmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;Go&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Add&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;an&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;unpublished&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;post&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;published&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;one&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Then&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;open&lt;/span&gt; &lt;span class=&#34;sb&#34;&gt;`./manage shell`&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;check&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;the&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;difference&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;between&lt;/span&gt; &lt;span class=&#34;sb&#34;&gt;`Entry.objects.all()`&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;sb&#34;&gt;`Entry.objects.published()`&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;markdown&#34;&gt;Markdown&lt;/h4&gt;
&lt;ol start=&#34;6&#34;&gt;
&lt;li&gt;Install django-markdown&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;    pip install django-markdown
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;7&#34;&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;&amp;quot;django_markdown&amp;quot;&lt;/code&gt; to INSTALLED_APPS.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add a second line to &lt;code&gt;qblog/urls.py&lt;/code&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^markdown/&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;django_markdown.urls&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;9&#34;&gt;
&lt;li&gt;Change &lt;code&gt;blog/admin.py&lt;/code&gt; to:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django_markdown.admin&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;MarkdownModelAdmin&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;EntryAdmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MarkdownModelAdmin&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;Enter&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;test&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;entries&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;now&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;sidenote&#34;&gt;
&lt;a name=&#34;markdown_issue&#34; id=&#34;markdown_issue&#34;&gt;&lt;/a&gt;
&lt;b&gt;Markdown Editor Toolbar Not Showing in Admin?&lt;/b&gt;
&lt;p&gt;Despite this being a Python 3.x tutorial, many have tried this in Python 2.x. Which is great, but the snazzy Markdown Editor in admin seems to be missing for them.&lt;/p&gt;
&lt;p&gt;When I had checked, I found that the Markdown widget&#39;s media i.e. javascript and stylesheets were not getting added in admin. A workaround is to explicitly define &lt;code&gt;form_overrides&lt;/code&gt; as follows.&lt;/p&gt;
&lt;pre&gt;
  from django_markdown.widgets import AdminMarkdownWidget
  from django.db.models import TextField
&lt;p&gt;class EntryAdmin(MarkdownModelAdmin):
list_display = (&amp;ldquo;title&amp;rdquo;, &amp;ldquo;created&amp;rdquo;)
prepopulated_fields = {&amp;ldquo;slug&amp;rdquo;: (&amp;ldquo;title&amp;rdquo;,)}
# Next line is a workaround for Python 2.x
formfield_overrides = {TextField: {&amp;lsquo;widget&amp;rsquo;: AdminMarkdownWidget}}
&lt;/pre&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h4 id=&#34;index-view&#34;&gt;Index View&lt;/h4&gt;
&lt;ol start=&#34;10&#34;&gt;
&lt;li&gt;Change &lt;code&gt;blog/views.py&lt;/code&gt; to:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.views&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;generic&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;BlogIndex&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;generic&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ListView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;queryset&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;published&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;template_name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;home.html&amp;#34;&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;paginate_by&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;11&#34;&gt;
&lt;li&gt;Create a url mapping in &lt;code&gt;qblog/urls.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;urlpatterns&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;patterns&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
        &lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^admin/&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;site&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;urls&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^markdown/&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;django_markdown.urls&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;blog.urls&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)),&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;12&#34;&gt;
&lt;li&gt;Create &lt;code&gt;blog/urls.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.conf.urls&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;patterns&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;views&lt;/span&gt;

    &lt;span class=&#34;n&#34;&gt;urlpatterns&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;patterns&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
        &lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^$&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;views&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;BlogIndex&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;as_view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;index&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;index-template&#34;&gt;Index Template&lt;/h4&gt;
&lt;ol start=&#34;13&#34;&gt;
&lt;li&gt;Make template and static directories. Then, copy the &lt;a href=&#34;https://github.com/arocks/qblog&#34;&gt;files&lt;/a&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;    mkdir templates
    cp -R /somewhere/templates/* templates
    mkdir static
    cp -R /somewhere/static/* static
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;14&#34;&gt;
&lt;li&gt;Create &lt;code&gt;templates/home.html&lt;/code&gt; with:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;    {% extends &amp;#34;base.html&amp;#34; %}
    {% load django_markdown %}

    {% block blog_entries %}
    {% for object in object_list %}
      &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;div&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;class&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;post&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;h2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;{{ object.title }}&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;h2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;class&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;meta&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;{{ object.created }}&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
        {{ object.body|markdown }}
      &lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;div&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
    {% endfor %}
    {% endblock %}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;15&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;qblog/settings.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;TEMPLATE_DIRS&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;os&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;BASE_DIR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;templates&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;n&#34;&gt;STATICFILES_DIRS&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;os&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;path&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;BASE_DIR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;static&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;Refresh&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;the&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;home&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;page&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;now&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Enjoy&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;the&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;first&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;non&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;page&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;feed&#34;&gt;Feed&lt;/h4&gt;
&lt;ol start=&#34;23&#34;&gt;
&lt;li&gt;Create &lt;code&gt;blog/feed.py&lt;/code&gt; with:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.contrib.syndication.views&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Feed&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;blog.models&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;LatestPosts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Feed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;title&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Q Blog&amp;#34;&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;link&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;/feed/&amp;#34;&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;description&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Latest Posts&amp;#34;&lt;/span&gt;

        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;items&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;published&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()[:&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;24&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;blog/urls.py&lt;/code&gt; (last but one line):&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;.&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;views&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;feed&lt;/span&gt;
    
    &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^feed/$&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;feed&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;LatestPosts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;feed&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;25&#34;&gt;
&lt;li&gt;Mention in the &lt;code&gt;templates/base.html&lt;/code&gt; template&amp;rsquo;s &lt;code&gt;HEAD&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;    &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;link&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;href&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;/feed/&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;rel&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;alternate&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;application/rss+xml&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;title&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Q Blog Feed&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;/&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;entry-view&#34;&gt;Entry View&lt;/h4&gt;
&lt;ol start=&#34;16&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;blog/views.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;BlogDetail&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;generic&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DetailView&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;template_name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;post.html&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;17&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;blog/urls.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;^entry/(?P&amp;lt;slug&amp;gt;\S+)$&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;views&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;BlogDetail&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;as_view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;entry_detail&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;18&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;blog/models.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;EntryQuerySet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;as_manager&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_absolute_url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;reverse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;entry_detail&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;kwargs&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;slug&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;slug&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;entry-template&#34;&gt;Entry Template&lt;/h4&gt;
&lt;ol start=&#34;19&#34;&gt;
&lt;li&gt;Open &lt;code&gt;templates/home.html&lt;/code&gt; and save it as &lt;code&gt;post.html&lt;/code&gt; while removing
the for loop, like this:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;    {% extends &amp;#34;base.html&amp;#34; %}
    {% load django_markdown %}

    &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;div&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;class&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;post&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;h2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;href&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;{% url &amp;#34;&lt;/span&gt;&lt;span class=&#34;na&#34;&gt;entry_detail&lt;/span&gt;&lt;span class=&#34;err&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;slug&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;object.slug&lt;/span&gt; &lt;span class=&#34;err&#34;&gt;%}&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;{{ object.title }}&lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;h2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;class&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;meta&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
        {{ object.created }} |
        Tagged under {{  object.tags.all|join:&amp;#34;, &amp;#34; }}
      &lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
      {{ object.body|markdown }}
    &lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;div&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;

Update `templates/home.html` with the same `&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;h2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;` line.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;tags&#34;&gt;Tags&lt;/h4&gt;
&lt;ol start=&#34;20&#34;&gt;
&lt;li&gt;Add tags to &lt;code&gt;blog/models.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Tag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;slug&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SlugField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;max_length&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;unique&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;fm&#34;&gt;__str__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;slug&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;o&#34;&gt;....&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;tags&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ManyToManyField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;20&#34;&gt;
&lt;li&gt;Migrate:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;    ./manage.py makemigrations blog
    ./manage.py migrate blog
&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;21&#34;&gt;
&lt;li&gt;Add to &lt;code&gt;blog/admin.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;n&#34;&gt;admin&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;site&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;register&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;models&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;22&#34;&gt;
&lt;li&gt;Change template &lt;code&gt;templates/post.html&lt;/code&gt; to:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;    &lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;class&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;meta&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;{{ object.created }} |
      Tagged under {{ object.tags.all|join:&amp;#34;, &amp;#34; }}
    &lt;span class=&#34;p&#34;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;testing&#34;&gt;Testing&lt;/h4&gt;
&lt;ol start=&#34;23&#34;&gt;
&lt;li&gt;Add these two test cases in &lt;code&gt;blog/tests.py&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.test&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;TestCase&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;django.contrib.auth&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;get_user_model&lt;/span&gt;
    &lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;.models&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;BlogPostTest&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TestCase&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;

        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;test_create_unpublished&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;entry&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;title&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Title Me&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;publish&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;save&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
            &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;assertEqual&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;all&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
            &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;assertEqual&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;published&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;publish&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;True&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;save&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
            &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;assertEqual&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Entry&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;objects&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;published&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;


    &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;BlogViewTests&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;TestCase&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
        &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;test_feed_url&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;
            &lt;span class=&#34;n&#34;&gt;response&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;client&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;get&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;/feed/&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
            &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;assertIn&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;xml&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;response&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;24&#34;&gt;
&lt;li&gt;Run the tests by &lt;code&gt;./manage.py test blog&lt;/code&gt; and they should both pass.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;final-notes&#34;&gt;Final Notes&lt;/h3&gt;
&lt;p&gt;The entire source is available on &lt;a href=&#34;https://github.com/arocks/qblog&#34;&gt;Github&lt;/a&gt;. If you face any issues, make sure that you are running the same Python/Django versions and compare your code with mine.&lt;/p&gt;
&lt;p&gt;As always, I would love to hear your comments and feedback.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>An Easy Guide to Install Python or Pip on Windows</title>
      <link>https://arunrocks.com/guide-to-install-python-or-pip-on-windows/</link>
      <pubDate>Mon, 30 Dec 2013 21:49:00 +0530</pubDate>
      
      <guid>https://arunrocks.com/guide-to-install-python-or-pip-on-windows/</guid>
      <description>&lt;div class=&#34;sidenote&#34;&gt;
    &lt;p&gt;[Updated 2017-04-15] These steps might not be required in latest Python distributions which are already shipped with &lt;code&gt;pip&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I enjoy studying other people&amp;rsquo;s development environments. They give me plenty of insights into their aesthetic choices and their productivity shortcuts. But I have seen a lot of horrible environments cobbled together by flaky batch files that are one update away from blowing up, often leaving no option but to reinstall everything from scratch. Unfortunately, they have all been Windows environments.&lt;/p&gt;
&lt;p&gt;Recently, I tried to install Python and pip on a Windows laptop. Though I have installed Python on Windows XP and Windows Servers for several years till 2010; there have been a lot of changes both in the Windows world such as Powershell and the Python world. So there is a lot of confusing information out there for the Python beginner. And then there is Python 3. Sigh!&lt;/p&gt;
&lt;p&gt;Suffice to say I wanted to share what I learnt in a video aimed at the Python beginner or anyone struggling to install Python on Windows. The video and the high-level transcript follows:&lt;/p&gt;
&lt;h4 id=&#34;what-is-covered&#34;&gt;What is covered?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Installing Python 2 or Python 3 on Windows 7&lt;/li&gt;
&lt;li&gt;Installing pip from PowerShell&lt;/li&gt;
&lt;li&gt;Setting up a virtualenv&lt;/li&gt;
&lt;li&gt;Installing via pip&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&#34;http://www.youtube.com/watch?v=yHtFeEZEexc&amp;hd=1&#34;&gt;&lt;img src=&#34;https://arunrocks.com/static/images/blog/video-thumbnail.png&#34; width=&#34;350&#34; height=&#34;174&#34; alt=&#34;Screencast&#34; title=&#34;Go to the Screencast on YouTube&#34;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;how-to-install-python--pip-on-windows-7-or-8&#34;&gt;How to install Python / Pip on Windows 7 (or 8)&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Download the MSI installer from &lt;a href=&#34;http://www.python.org/download/&#34;&gt;http://www.python.org/download/&lt;/a&gt;. Select 32 bit or 64 bit based on the System Settings which opens by pressing Win+Break&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the installer. Be sure to check the option to add Python to your PATH while installing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open PowerShell as admin by right clicking on the PowerShell icon and selecting &amp;lsquo;Run as Admin&amp;rsquo;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To solve permission issues, run the following command:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-PowerShell&#34; data-lang=&#34;PowerShell&#34;&gt;&lt;span class=&#34;nb&#34;&gt;Set-ExecutionPolicy&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Unrestricted&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the following commands in PowerShell to download the bootstrap scripts for &lt;code&gt;easy_install&lt;/code&gt; and &lt;code&gt;pip&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-PowerShell&#34; data-lang=&#34;PowerShell&#34;&gt;&lt;span class=&#34;n&#34;&gt;mkdir&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;envs&lt;/span&gt;
&lt;span class=&#34;nb&#34;&gt;cd &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;c:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;envs&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;new-object&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;System&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;WebClient&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DownloadFile&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;https://bootstrap.pypa.io/ez_setup.py&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;   &lt;span class=&#34;s1&#34;&gt;&amp;#39;c:\envs\distribute_setup.py&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;new-object&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;System&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Net&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;WebClient&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DownloadFile&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;https://raw.github.com/pypa/pip/master/contrib/get-pip.py&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;c:\envs\get-pip.py&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;python&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;envs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;distribute_setup&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;py&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;python&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;envs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;get-pip&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;py&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once these commands run successfully, you can delete the scripts &lt;code&gt;get-pip.py&lt;/code&gt; and &lt;code&gt;distribute_setup.py&lt;/code&gt;&lt;/p&gt;
 &lt;div class=&#34;sidenote&#34;&gt;
 &lt;a name=&#34;distribute_issue&#34; id=&#34;distribute_issue&#34;&gt;&lt;/a&gt;
 &lt;b&gt;HTTP Issue with distribute_setup.py?&lt;/b&gt;
 &lt;p&gt;[Updated 2015-03-05] The script distribute_setup is no longer available at its &lt;a href=&#34;http://python-distribute.org/distribute_setup.py&#34;&gt;old location&lt;/a&gt;. Thanks to Rudhra for sharing the new location.&lt;/p&gt;
 &lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now typing &lt;code&gt;easy_install&lt;/code&gt; or &lt;code&gt;pip&lt;/code&gt; should work. If it doesn&amp;rsquo;t it means the Scripts folder is not in your path. Run the next command in that case (Note that this command must be run only once or your PATH will get longer and longer). Make sure to replace &lt;code&gt;c:\Python33\Scripts&lt;/code&gt; with the correct location of your Python installation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-PowerShell&#34; data-lang=&#34;PowerShell&#34;&gt;&lt;span class=&#34;n&#34;&gt;setx&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;PATH&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;%PATH%;C:\Python33\Scripts&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Close and reopen PowerShell after running this command.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To create a Virtual Environment, use the following commands:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-PowerShell&#34; data-lang=&#34;PowerShell&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;c:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;python&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;pip&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;install&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;virtualenv&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;virtualenv&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acme&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;.\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;acme&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Scripts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;\&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;activate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ps1&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;pip&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;install&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;IPython&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;ipython3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s it! I suppose the same steps work for Windows 8 as well. But I don&amp;rsquo;t have a machine to try it out. Do let me know if this worked for you.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
</description>
    </item>
    
  </channel>
</rss>
