Weekly letter pythonprogramming.email
To get the curated list of awesome python articles from all over the Internet, please subscribe with pythonprogramming.email. This is specifically suitable for beginners.
Advertise with us
Django-app   0   2131
Hello Word in Django : How to start with Django

In this article I will teach you how to make and run a python-django app in less than 5 minutes.

Prerequisite: Python (preferably python 3) is already installed.

Step to create and run the django app:

Install virtual environment. You may proceed without virtual environment too, but in long run it is going to be very helpful. $ pip install virtualenv

Create a virtual environment.
$ virtualenv -p /usr/bin/python3 helloworld_VE

Activate the virtual environment.
$ source helloworld_VE/bin/activate

Install the latest django framework in virtual environment.
$ pip install django

Create your project. 
$ django-admin startproject myproject

Go inside newly created project directory. 
$ cd myproject

You will see a file manage.py  and a directory with same name as of your project.

create an app here. Every project consist of one or more apps. These are plug-able modules which can be reused in other project if written properly. 
$ python manage.py startapp helloworld

Go inside helloworld  directory. create a new file urls.py .

Add below lines to this file and save it.

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),

Open views file and save below code in it. 

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello World. First Django Project. ThePythonDjango.Com")

Include the app i.e. helloworld urls in main project urls file. Open myproject/urls.py file and make add below line in urlpatterns. url(r'^helloworld/',include('helloworld.urls')),

Also import include module.
from django.conf.urls import include

Now finally add helloworld  in installed apps in myproject/settings.py file .

Now run command. 
$ python manage.py runserver .

This will run the python http server on localhost and 8000 port. If you want to run it on different port, use port number in command. $ python manage.py runserver 8888 . To run it on different IP address, pass the IP address as well. Use this command to make your project available for everyone on the network.$ python manage.py runserver

So this was basic tutorial to set up django app in less than 5 minute. You can refer below github code and  video for same.   

Code on Github:
Github URL : https://github.com/anuragrana/hellow-world-django.git   


Hosting django app on server:

Read how you can host your django app on pythonanywhere server for free. A complete step by step guide with all screenshots and video.


How to install virtual environment? Django official tutorials.

Django-app   0   2131

0 thoughts on 'Hello Word In Django : How To Start With Django'
Leave a comment:

*All Fields are mandatory. **Email Id will not be published publicly.

Please subscribe to get the latest articles in your mailbox.

© 2017-2020 Python Circle   Contact   Sponsor   Archive   Sitemap