<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Prabeen&#039;s Blog &#187; Python</title>
	<atom:link href="http://prabeengiri.com.np/category/python/feed" rel="self" type="application/rss+xml" />
	<link>http://prabeengiri.com.np</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 04 Jan 2011 18:31:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hello world application using Django framework(Python)</title>
		<link>http://prabeengiri.com.np/python/hello-world-application-using-django-framework.html</link>
		<comments>http://prabeengiri.com.np/python/hello-world-application-using-django-framework.html#comments</comments>
		<pubDate>Mon, 22 Feb 2010 12:48:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[hello world using djano]]></category>
		<category><![CDATA[start django]]></category>
		<category><![CDATA[view and urlconf]]></category>

		<guid isPermaLink="false">http://prabeengiri.com.np/?p=371</guid>
		<description><![CDATA[Hello world web application using django a python web development framework, starting with view and urlconf in django. view and url mapping in django , start django , deploy django. ]]></description>
			<content:encoded><![CDATA[<p>In my previous post I have written about the django installation in windows platform and run django development server. In this post I will go through the steps about how to create &#8216;hello world&#8217;  application using python web development framework i.e  django . If you have problem about django installation and creating project in django then please refer to this <a title="Django Installation" href="http://prabeengiri.com.np/python/djangopython-web-development-framework-installation-in-windows.html" target="_blank">post</a> .<span id="more-371"></span></p>
<p>Here I will assume that you have successfully installed django and created project  named let say &#8216;mysite&#8217;. Now I will go with the step by step process about creating hello world application .</p>
<p>Go to command prompt and navigate to the  django  project folder and type &#8220;manage.py runserver&#8221; to start the server for that particular project. By default, the <tt><span><strong>runserver</strong></span></tt> command starts the development server on port 8000, listening only for local connections. If you want to change the server’s port, pass it as a command-line argument:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">python manage.<span style="color: black;">py</span> runserver <span style="color: #ff4500;">8080</span></pre></div></div>

<p>Now we have server running at port 8000 unless any port is defined.</p>
<p>With Django the contents of the page are produced by a view function, and the URL is specified in a URLconf. First, let’s write our “Hello world” view function in &#8216;views.py&#8217; that we have inside the project folder.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">http</span> <span style="color: #ff7700;font-weight:bold;">import</span> HttpResponse
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> hello<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
<span style="color: #ff7700;font-weight:bold;">return</span> HttpResponse<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello world&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>In the above code we have imported the HttpResponse class from the django.http class. Then we have defined the hello function which returns the http respose &#8220;hello world&#8221; . It is required to pass the view parameter as &#8216;request&#8217; though it has no any use.</p>
<p>Url Configuration File.<br />
In the project folder we can  see the url.py file where we define the patter of the url and its respective view .  Basically, it’s a mapping between URLs and the view functions that should be called for those URLs . For example, “When somebody visits the URL <tt><span>/prabeen/</span></tt>,  call the view function <tt>prabeen<span>_view()</span></tt>,  which lives in the Python module <tt><span>views.py</span></tt>”. By default url.py file will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">urls</span>.<span style="color: black;">defaults</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Uncomment the next two lines to enable the admin:</span>
<span style="color: #808080; font-style: italic;"># from django.contrib import admin</span>
<span style="color: #808080; font-style: italic;"># admin.autodiscover()</span>
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
    <span style="color: #808080; font-style: italic;"># Example:</span>
    <span style="color: #808080; font-style: italic;"># (r'^mysite/', include('mysite.foo.urls')),</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Uncomment the admin/doc line below and add 'django.contrib.admindocs'</span>
    <span style="color: #808080; font-style: italic;"># to INSTALLED_APPS to enable admin documentation:</span>
    <span style="color: #808080; font-style: italic;"># (r'^admin/doc/', include('django.contrib.admindocs.urls')),</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Uncomment the next line to enable the admin:</span>
    <span style="color: #808080; font-style: italic;"># (r'^admin/', include(admin.site.urls)),</span>
<span style="color: black;">&#41;</span></pre></div></div>

<p>The first line imports all objects from the django.conf.urls.defaults module, which is Django’s URLconf infrastructure. This includes a function called patterns where we define the url patters for our view module. Now lets define the url patterns for the hello function of view module. Before this we have to import the hello view from the view function . Now our code goes like below for the url.py file.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">urls</span>.<span style="color: black;">defaults</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> mysite.<span style="color: black;">views</span> <span style="color: #ff7700;font-weight:bold;">import</span> hello
<span style="color: #808080; font-style: italic;"># Uncomment the next two lines to enable the admin:</span>
<span style="color: #808080; font-style: italic;"># from django.contrib import admin</span>
<span style="color: #808080; font-style: italic;"># admin.autodiscover()</span>
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
<span style="color: #808080; font-style: italic;"># Example:</span>
<span style="color: #808080; font-style: italic;"># (r'^mysite/', include('mysite.foo.urls')),</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Uncomment the admin/doc line below and add 'django.contrib.admindocs'</span>
<span style="color: #808080; font-style: italic;"># to INSTALLED_APPS to enable admin documentation:</span>
<span style="color: #808080; font-style: italic;"># (r'^admin/doc/', include('django.contrib.admindocs.urls')),</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Uncomment the next line to enable the admin:</span>
<span style="color: #808080; font-style: italic;"># (r'^admin/', include(admin.site.urls)),</span>
<span style="color: black;">&#41;</span>
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">'^hello/$'</span>, hello<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: black;">&#41;</span></pre></div></div>

<p>Here we have imported  the hello view form the view module that we have in project folder. And at the bottom we have defined the url pattern for the hello view  i.e &#8216;^hello/#&#8217; to make sure that our hello view executes if  &#8216;hello/&#8217; is found in the url . In the same manner we can add the url patterns for other view function . Django URLconfs allow arbitrary regexes for powerful URL matching, you’ll probably only use a few regex symbols in practice.</p>
<p>Now its time to bring our work into action. Go to browser and type <strong> &#8220;http://localhost:8000/hello/&#8221; </strong>, you will see  &#8216;hello world&#8217; printed in the browser. In the following way we can map the url with the other view functions in the URL confs.</p>
]]></content:encoded>
			<wfw:commentRss>http://prabeengiri.com.np/python/hello-world-application-using-django-framework.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django (Python Web Developement Framework)  Installation in Windows</title>
		<link>http://prabeengiri.com.np/python/djangopython-web-development-framework-installation-in-windows.html</link>
		<comments>http://prabeengiri.com.np/python/djangopython-web-development-framework-installation-in-windows.html#comments</comments>
		<pubDate>Mon, 21 Dec 2009 06:45:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[MVC architechture]]></category>
		<category><![CDATA[web development framework]]></category>

		<guid isPermaLink="false">http://prabeengiri.com.np/?p=130</guid>
		<description><![CDATA[Django installation in windows, Django python web development framework. Python web development framework, Django Installation ]]></description>
			<content:encoded><![CDATA[<p>It  took me about five different installation guides, but I finally got Django to work on my Windows XP .</p>
<p>Here&#8217;s a a simpe step for those who were having hard time in django installation in windows.</p>
<p><strong>1.</strong> Download Python 2.6 from <a title="Download python" href="http://www.python.org/download/ " target="_blank">here</a>.</p>
<p><strong>2.</strong> Download latest version of Django  from<a href="http://www.djangoproject.com/download/" target="_blank"> here</a>.  Extract the file on  C drive.  which makes <strong>c:/Django</strong>.<span id="more-130"></span></p>
<p><strong>3.</strong> You can see <strong>setup.py</strong> file under <strong>c:/Django</strong> folder.</p>
<p><strong>4.</strong> Go to windows command prompt and navigate to the <strong>c:/Django</strong> folder and enter</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">python setup.py install</pre></div></div>

<p>. For this you should have set the python folder to  the path of windows . You can do this by<br />
=&gt; Right click on “My Computer” and select Properties. Go to advanced, then Environment Variables at the bottom. Edit “Path” and enter the above path &#8221;<strong>c:\Python26”</strong></p>
<p><strong>5.</strong> Now you can see the django installed on the comment prompt. Its not finished yet.</p>
<p><strong>6.</strong> Navigate to the</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">C:\Python26\Lib\site-packages\</pre></div></div>

<p>. You can see  directory named &#8216;Django&#8217; which ensures that django has been successfully installed in your system.</p>
<p><strong>Now its time to create project  and run server .</strong></p>
<p><strong>7.</strong> Go to command prompt and navigate to</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">C:\Python26\Lib\site-packages\django\bin&gt;</pre></div></div>

<p>and enter &#8216;</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">django-admin.py startproject mysite</pre></div></div>

<p>&#8216; without single quote. This will create your project inside the bin folder with name  &#8216;mysite&#8217;.</p>
<p><strong>8.</strong> Again go to command prompt and naviagate to</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">C:\Python26\Lib\site-packages\django\bin\mysite&gt;</pre></div></div>

<p>and enter</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">manage.py runserver</pre></div></div>

<p>and go to your browser and type</p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">http://127.0.0.1:8000/</pre></div></div>

<p>You can see the page like this:<br />
<img class="alignnone size-full wp-image-135" title="Djangopart2_1" src="http://prabeengiri.com.np/wp-content/uploads/2009/12/Djangopart2_1.jpg" alt="Djangopart2_1" width="100%" /></p>
<p><strong><em>This is how I made django installed on my windows xp. Hope you will find this steps useful to start with django installation and start your django web application .A good alternative for django installation in windows will be <a href="http://www.instantdjango.com/" target="_blank">instantDjango </a>like we have instantrails for ruby on rails.</em></strong></p>
<p><strong>About creating &#8216;helloworld&#8217; web application I will soon update this post.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://prabeengiri.com.np/python/djangopython-web-development-framework-installation-in-windows.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

