UrbanPro
true

Learn django from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Django First Application

S
Sharma academy
06/09/2018 0 0

Install Django

Before you can use Django, you’ll need to install it. Our complete installation guide covers all the possibilities; this guide will get you to a simple, minimal installation that’ll work while you walk through the introduction.

For linux :

pip install django

For Windows :

python -m pip install django

Verify installation

on python terminal we will write

>>> print(django.get_version())2.1

Write your first Django app

Open command prompt to create new django project we should write on terminal the following command :

>> django-admin  startproject firstdemoproject 

now we will move to the folder and create a new app inside project folder

 >>cd firstdemoproject >> django-admin startapp app1

it will create required folders inside the directory structure.

Register your App

â??â??â??â??manage.pyâ??â??â??â??app1â??        settings.pyâ??        urls.pyâ??        wsgi.pyâ??        __init__.pyâ??â??â??â??requirements.txt

find the file with name settings.py and inside that file look for following code :

INSTALLED_APPS = [    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles','app1']

add your app name as the last entry in the file and save and close the file.
A view is a place where we put the "logic" of our application, a webpage is basically a view in django.

Adding code to views.py

from django.shortcuts import renderfrom django.http import request,HttpResponsedef homepage(request):    return HttpResponse("this is first page")

save and close the file.

Adding url to urls.py

from  app1.views import homepageurlpatterns = [    path('admin/', admin.site.urls),    path('homepage/',homepage)]

now to Run the program type the following command at command prompt as folows :

>>python manage.py runserver

while your program is in running state ,open your browser and open url as follows :

http://localhost:8000/homepage

it will display your very first django app.

Woaw!! what a beautiful start !!

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Learn Django in 20 steps
1.>pip install Django 2. >mkdir c:\test\crud 3. >cd c:\test\crud 4. c:\test\crud>django-admin startproject web 5. >cd c:\test\crud\web 6. c:\test\crud\web>manage.py runserver 7....

web scrapping using scrapy Python
Overview of Scrapy Scrapy is a Python framework for large scale web scraping. It gives you all the tools you need to efficiently extract data from websites, process them as you want, and store them in...
S

Sharma academy

0 0
0

Looking for django ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for django Classes?

The best tutors for django Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn django with the Best Tutors

The best Tutors for django Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more