How to write Hello World program in Django? How to start with Django?

If you're going to do Django Training in Noida, then ShapeMySkills Pvt Ltd Institute is the best option for you.

Django is a high-level Python web mesh. It helps in faster evolution, polished and sensible design. Developed by skillful developers, the app takes care of much of the inconvenience of web development, so a user can focus on writing the app. It is free, open-source, and it is incredibly fast. This app is famous for its distinctive and well-controlled app framework. Some of Django's favorite apps are Instagram, Spotify, Pinterest, Mozilla, and National Geographic.

How to Create and Run the Django App:

First of all, install the virtual environment. Of course, you can continue without the virtual environment, but the virtual environment can be conducive later on.

$ pip install virtualenv

 

Generate a Virtual Environment

$ virtualenv –p /usr/bin/python3 helloworld_VE

Turn on the Virtual Environment

$ sourcehelloworld_VE/bin/activate

Establish the Newest Django Framework in the Virtual Environment

$ pip install Django

Generate a Project

$ Django-admin startproject myproject

Proceed inside the Newly Created Project Directory

$ cd myproject

You will be able to view a file named manage.py and also there will be a directory with the same name as the project.

You can make the app here.Every project includes one or more than one app.All of these apps are plug-able modules which means that you can reutilize them again in some other project if it was written properly.

$ python manage.py startapp helloworld

Now proceed inside helloworld directory and generate a new file named urls.py

Now write the lines given below to this file and save the file.

from Django.conf.urls import url

from . import views

urlpatterns=[

       url(r ‘ ^ $ ‘ ,views.index , name=’index’),

]

Now open the views file and save the code given below in it.

from djnago.shortcuts import render

from django.http import HttpResponse 

def index(request):

       return HttpResponse(“Hello World. First Django Project.PythonCircle.Com”)

Now incorporate the URLs of helloworld app in the main project URLs file.

After this open myproject/urls.py file and make an addition of the line below in urlpatterns

url(r ‘ ^helloworld/’, include(‘helloworld.urls’)),

After this include the import module

From django.conf.urls import include

Now ultimately add on helloworld in already installed apps in myproject/settings.py file

After this begin the Django development server by running the code.

$ python manage.py runserver

Now this will be able to run the Python HTTP server on the localhost and also on 8000 port. If you are willing to run it on a different port then you have to use the port number in the command. For an instance $ python manage.py runserver 8888.

Now make use of this command in order to make your project available to everyone on the network.

$ python manage.py runserver 0.0.0.0:8000

This was a basic tutorial for beginners to install the Django app and also start using it in about 5 minutes.

Conclusion - 

If you want to be a Django expert, you must join the best institute to kick-start your Django Training. If you're going to do Django Training in Noida, then ShapeMySkills Pvt Ltd Institute is the best option for you. 


Rahul Sharma

1 Blog posts

Comments