<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Babak Nikanjam</title>
    <description>The latest articles on DEV Community by Babak Nikanjam (@bnikanjam).</description>
    <link>https://dev.to/bnikanjam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F172470%2Fc73957aa-e557-481f-b4b6-07a5b428b067.jpeg</url>
      <title>DEV Community: Babak Nikanjam</title>
      <link>https://dev.to/bnikanjam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bnikanjam"/>
    <language>en</language>
    <item>
      <title>Django Hello World!</title>
      <dc:creator>Babak Nikanjam</dc:creator>
      <pubDate>Mon, 21 Oct 2019 06:40:08 +0000</pubDate>
      <link>https://dev.to/bnikanjam/django-as-a-micro-frame-work-3l2m</link>
      <guid>https://dev.to/bnikanjam/django-as-a-micro-frame-work-3l2m</guid>
      <description>&lt;p&gt;Django is a secure, tested and battery included Python web frame work comes with a powerful ORM and migration, a different approach of developing web apps (solving the web request-response problem) called Model-View-Template in contrast with MVC, and often considered very opinionated.&lt;/p&gt;

&lt;p&gt;One may think it's clunky and unnecessarily complicated for simple tasks. In the last US DjangoCon in September 2019, Carlton Gibson a respected friendly core Django veteran, beautifully shows that at core all web frame works are trying to solve the same problem and it is possible that Django too can be scraped down to a skinny single Python script for a Hello World! But Django is evolved to be what it is today to solve real world problems for rapid development and pragmatic design.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.conf&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.core.handlers.wsgi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WSGIHandler&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.http&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HttpResponse&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;

&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ROOT_URLCONF&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello_world&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;HttpResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Hello World!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hello_world&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;webapp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WSGIHandler&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, lets install Gunicorn HTTP WSGI web server in a new environment to catch and hand over any request coming its way to our web app!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;Pipenv &lt;span class="nb"&gt;install &lt;/span&gt;gunicorn
&lt;span class="nv"&gt;$ &lt;/span&gt;Pipenv shell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's run and introduce the web server to our minimalist web app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gunicorn app:webapp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above command, the left of the colon is the python script file name our code lives in and the right of the colon is the name of the &lt;br&gt;
function calling our web app.&lt;/p&gt;

&lt;p&gt;Now navigate to &lt;a href="http://127.0.0.1:8000/"&gt;http://127.0.0.1:8000/&lt;/a&gt; for a nice greeting!&lt;/p&gt;

&lt;p&gt;Carlton Gibson talk at DjangoCon 2019 &lt;a href="https://www.youtube.com/watch?v=w9cYEovduWI&amp;amp;t=0s"&gt;Django as a Micro-Framework&lt;/a&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>webdev</category>
      <category>python</category>
    </item>
  </channel>
</rss>
